「VB.net」正規表現で区切り文字を指定する

2021年9月10日

書式
Regex.Split(文字列,正規表現)
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
' 変数の宣言
Dim target As String = "test+23_csv+56_de"
'+または_正規表現
Dim res() As String = Regex.Split(target, "[+_]")
'配列の要素を取り出す
For Each ele In res
Console.WriteLine(ele)
Next
Console.WriteLine(res.Length)
Console.ReadKey()
End Sub
End Module
Imports System.Text.RegularExpressions Module Module1 Sub Main() ' 変数の宣言 Dim target As String = "test+23_csv+56_de" '+または_正規表現 Dim res() As String = Regex.Split(target, "[+_]") '配列の要素を取り出す For Each ele In res Console.WriteLine(ele) Next Console.WriteLine(res.Length) Console.ReadKey() End Sub End Module
Imports System.Text.RegularExpressions

Module Module1

    Sub Main()

        ' 変数の宣言
        Dim target As String = "test+23_csv+56_de"
        '+または_正規表現
        Dim res() As String = Regex.Split(target, "[+_]")

        '配列の要素を取り出す
        For Each ele In res
            Console.WriteLine(ele)
        Next
        Console.WriteLine(res.Length)

        Console.ReadKey()

    End Sub

End Module

結果
test
23
csv
56
de
5

VB.net

Posted by arkgame