using System;
namespace Strings1
{
/// <summary>
/// Class1 の概要の説明です。
/// </summary>
class Class1
{
/// <summary>
/// アプリケーションのメイン エントリ ポイントです。
/// </summary>
[STAThread]
static void Main(string[] args)
{
string jstr1 = "こんにちは";
string jstr2 = "世界";
string jstr3 = "こんにちあ";
string jstr4 = "こんにちは";
string jstr5 = "こんにちひ";
string estr1 = "Hello";
string estr2 = "World";
Console.WriteLine( "\n左寄せ" );
Console.WriteLine( "PadLeft():>>>{0}<<<", jstr1.PadLeft(10, '-') );
Console.WriteLine( "PadLeft():>>>{0}<<<", estr1.PadLeft(10) );
Console.WriteLine( "\n右寄せ" );
Console.WriteLine( "PadRight():>>>{0}<<<", jstr1.PadRight(10, '-') );
Console.WriteLine( "PadRight():>>>{0}<<<", estr1.PadRight(10) );
Console.WriteLine( "\n大文字へ" );
Console.WriteLine( "ToUpper():>>>{0}<<<", jstr1.ToUpper() );
Console.WriteLine( "ToUpper():>>>{0}<<<", estr1.ToUpper() );
Console.WriteLine( "\n小文字へ" );
Console.WriteLine( "ToLower():>>>{0}<<<", jstr1.ToLower() );
Console.WriteLine( "ToLower():>>>{0}<<<", estr1.ToLower() );
Console.WriteLine( "\nインデクサ" );
for(int i = 0; i < jstr1.Length; i++)
{
Console.WriteLine( "jstr1[{0}] = {1}", i, jstr1[i]);
}
Console.WriteLine( "\nCompare" );
Console.WriteLine( "Compare:{0} and {1} = {2}", jstr1, jstr3, String.Compare(jstr1, jstr3));
Console.WriteLine( "Compare:{0} and {1} = {2}", jstr1, jstr4, String.Compare(jstr1, jstr4));
Console.WriteLine( "Compare:{0} and {1} = {2}", jstr1, jstr5, String.Compare(jstr1, jstr5));
Console.WriteLine( "\nCompareTo" );
Console.WriteLine( "CompareTo:{0} and {1} = {2}", jstr1, jstr3, jstr1.CompareTo(jstr3));
Console.WriteLine( "CompareTo:{0} and {1} = {2}", jstr1, jstr4, jstr1.CompareTo(jstr4));
Console.WriteLine( "CompareTo:{0} and {1} = {2}", jstr1, jstr5, jstr1.CompareTo(jstr5));
Console.WriteLine( "\nEquals" );
Console.WriteLine( "Equals:{0} and {1} = {2}", jstr1, jstr3, jstr1.Equals(jstr3));
Console.WriteLine( "Equals:{0} and {1} = {2}", jstr1, jstr4, jstr1.Equals(jstr4));
Console.WriteLine( "\nStartsWith" );
Console.WriteLine( "StartsWith:{0} and {1} = {2}", jstr1, "こん", jstr1.StartsWith("こん"));
Console.WriteLine( "StartsWith:{0} and {1} = {2}", jstr1, "んこ", jstr1.StartsWith("んこ"));
Console.WriteLine( "\nEndsWith" );
Console.WriteLine( "EndsWith:{0} and {1} = {2}", jstr1, "ちは", jstr1.EndsWith("ちは"));
Console.WriteLine( "EndsWith:{0} and {1} = {2}", jstr1, "はち", jstr1.EndsWith("はち"));
Console.WriteLine( "\nCopyTo" );
char[] charArray = new char[jstr1.Length];
jstr1.CopyTo(0, charArray, 0, jstr1.Length);
for(int i = 0; i < jstr1.Length; i++)
{
Console.WriteLine( "charArray[{0}] = {1}", i, charArray[i]);
}
Console.WriteLine( "\nConcat" );
Console.WriteLine( "Concat:{0}, {1}, {2}, {3} = {4}", jstr1, jstr2, estr1, estr2, String.Concat(jstr1, jstr2, estr1, estr2));
Console.WriteLine( "\nInsert" );
Console.WriteLine( "Insert:{0}, {1} = {2}", jstr1, estr1, jstr1.Insert(3, estr1));
Console.WriteLine( "\nIndexOf" );
Console.WriteLine( "IndexOf:{0}, {1} = {2}", jstr1, "にち", jstr1.IndexOf("にち"));
Console.WriteLine( "\nReplace" );
Console.WriteLine( "Replace:{0}, {1} = {2}", jstr1, "にち→ち", jstr1.Replace("にち", "ち"));
{
Console.WriteLine( "\nSplit" );
string testString = "Hello World,This is a test";
char[] separator = {' ', ','};
string[] result;
Console.WriteLine( "Split:{0}, {1} = {2}", jstr1, testString, result = testString.Split(separator, 10));
int i = 0;
foreach(string str in result)
{
Console.WriteLine( "splitted[{0}] = {1}", i++, str);
}
}
Console.WriteLine( "\nTrim" );
string trim1 = "\n\t Hello World こんにちは 世界 \n\t";
char[] trimChar = {' ', '\t', '\n', ' '};
Console.WriteLine( "Trim:>>>{0}<<<\n>>>{1}<<<", trim1, trim1.Trim());
Console.WriteLine( "\nTrim:>>>{0}<<<\n>>>{1}<<<", trim1, trim1.Trim(trimChar));
Console.WriteLine( "\nTrimStart:>>>{0}<<<\n>>>{1}<<<", trim1, trim1.TrimStart(trimChar));
Console.WriteLine( "\nTrimEnd:>>>{0}<<<\n>>>{1}<<<", trim1, trim1.TrimEnd(trimChar));
Console.WriteLine( "\nSubstring" );
Console.WriteLine( "{0}.Substring(1, 3) = {1}", jstr1, jstr1.Substring(1, 3));
Console.WriteLine( "\nRemove" );
Console.WriteLine( "{0}.Remove(2, 1) = {1}", jstr1, jstr1.Remove(2, 1));
Console.ReadLine();
}
}
}
|