KITASENJU DESIGN BLOG

memo, html, javascript, unity

c# 文字列でsplit

コード

文字列でsplit

        string str = "1234 1234 unko 123 1131";
        string[] splitStr = {"unko"};
        string[] ary =  str.Split(splitStr, StringSplitOptions.None);

        Debug.Log(ary.Length);//2
        Debug.Log(ary[0]);//1234 1234 
        Debug.Log(ary[1]);// 123 1131

改行でsplit

        string[] brStr = {"\n"};
        string[] lines =  suuji.Split(brStr, StringSplitOptions.None);

        Debug.Log(lines.Length);
        Debug.Log(lines[1]);
        Debug.Log(lines[2]);
        Debug.Log(lines[3]);

参考

【C#入門】String.Splitで文字列を分割(複数文字、文字数でも分割) | 侍エンジニアブログ

"FOOTER"