文字列を区切り文字で配列にしたい
サンプルプログラム
文字列を配列に変換するには System.String クラスの Split メソッド又は Split 関数を使います。
以下のプログラムでは Split メソッドを使ってカンマ区切りで配列に変換しています。
Sub Main() Dim testStr As String = "abc,def,ghi" Dim testArray(2) As String 'カンマで文字列を区切る(引数はChar型なので文字列は指定できない) testArray = testStr.Split(",") '文字列を区切り文字にしたい場合 'testArray = Split(配列にしたい文字列, 区切り文字列) 'abc 'def 'ghi 'と表示される For Each Str As String In testArray Console.WriteLine(Str) Next End Sub
Splitの引数と戻り値
System.String.Splitメソッド
変換後の文字列=System.String.Split(Char 文字)Split関数
変換後の文字列=Split(String 変換したい文字列,String 区切り文字列)