ゲームが作れるようになるまでがんばる日記

ゲーム制作のことを中心にゲームに関することを書いています

テキストの分割

string型のテキストを区切り文字で分割するには、Splitメソッドを使う。たとえば、','で区切る場合は次の通り。

string text = "this,is,test";
string[] splittext = text.Split(',');

int num = splittext.Length;

foreach(string str in splittext)
{
    System.Console.WriteLine( str );
}

生成されたstringの配列の個数はLengthで取得できる。