[VB.NET]カンマで文字列を分割するサンプル

2021年9月10日

書式
文字列.Split(“,"c)

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Module Module1
Sub Main()
'カンマを含む文字列変数の宣言 末尾が空文字
Dim target As String = "AA,BB,CC,Dd,"
'カンマで分割
Dim resArr() As String = target.Split(","c)
Console.WriteLine(resArr.Length)
'For Each文で配列の要素を取り出す
For Each ra In resArr
Console.Write(ra)
Next
Console.ReadKey()
End Sub
End Module
Module Module1 Sub Main() 'カンマを含む文字列変数の宣言 末尾が空文字 Dim target As String = "AA,BB,CC,Dd," 'カンマで分割 Dim resArr() As String = target.Split(","c) Console.WriteLine(resArr.Length) 'For Each文で配列の要素を取り出す For Each ra In resArr Console.Write(ra) Next Console.ReadKey() End Sub End Module
Module Module1

    Sub Main()

        'カンマを含む文字列変数の宣言 末尾が空文字
        Dim target As String = "AA,BB,CC,Dd,"

        'カンマで分割
        Dim resArr() As String = target.Split(","c)

        Console.WriteLine(resArr.Length)
        'For Each文で配列の要素を取り出す
        For Each ra In resArr
            Console.Write(ra)
        Next

        Console.ReadKey()

    End Sub

End Module

結果
5
AABBCCDd

VB.net

Posted by arkgame