文字列操作

「文字列操作」の編集履歴(バックアップ)一覧に戻る

文字列操作 - (2015/04/11 (土) 23:08:09) のソース

-文字列の長さ
--b = a.Length;

-文字列の部分取り出し
--b = a.Substring(0, 2);	//先頭から2文字→文字
--b = a.Substring(1, 2);	//2文字目から3文字→字列
--b = a.Substring(1);	//3文字目以降全部→字列A

-文字列の分割
--string a = "name<>date<>text";
--分割文字を'<>'として分割する
--string[] b = a.Split("<>");
--b[0]にはname
--b[1]にはdate
--b[2]にはtextが入る

-文字列検索
--string a = "name<>date<>text";
--int b = a.IndexOf('<>');
--先頭を 0とした,最初に発見した文字の位置(=文字数)が入る
--この場合、b=4

-左右の空白をとる
--text = text.Trim()