「VB.NET」Splitメソッドで複数の区切り文字を指定して分割する
構文
Dim 変数名1() As char = { 区切り文字1, ・・・ }
Dim 変数名2() As データの型 = 対象文字列.Split(変数名1)
区切り文字を複数指定するには、区切り文字をchar型の配列に入れてSplitメソッドの引数に渡します。
使用例
Module Module1
Public Sub Main()
Dim target As String = "study/skill,become:smart"
'複数の区切り文字
Dim cutStr() As Char = {"/", ",", ":"}
'文字列を分割する
Dim result() As String = target.Split(cutStr)
Console.WriteLine("複数の区切り文字を指定して分割する結果: " & String.Join(" ", result))
Console.ReadKey()
End Sub
End Module
Module Module1
Public Sub Main()
Dim target As String = "study/skill,become:smart"
'複数の区切り文字
Dim cutStr() As Char = {"/", ",", ":"}
'文字列を分割する
Dim result() As String = target.Split(cutStr)
Console.WriteLine("複数の区切り文字を指定して分割する結果: " & String.Join(" ", result))
Console.ReadKey()
End Sub
End Module
Module Module1 Public Sub Main() Dim target As String = "study/skill,become:smart" '複数の区切り文字 Dim cutStr() As Char = {"/", ",", ":"} '文字列を分割する Dim result() As String = target.Split(cutStr) Console.WriteLine("複数の区切り文字を指定して分割する結果: " & String.Join(" ", result)) Console.ReadKey() End Sub End Module
実行結果
複数の区切り文字を指定して分割する結果: study skill become smart