本文整理匯總了VB.NET中System.Text.RegularExpressions.Regex.Split方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Regex.Split方法的具體用法?VB.NET Regex.Split怎麽用?VB.NET Regex.Split使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Text.RegularExpressions.Regex
的用法示例。
在下文中一共展示了Regex.Split方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Example
' 導入命名空間
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim pattern As String = "[a-z]+"
Dim input As String = "Abc1234Def5678Ghi9012Jklm"
Dim result() As String = Regex.Split(input, pattern,
RegexOptions.IgnoreCase,
TimeSpan.FromMilliseconds(500))
For ctr As Integer = 0 To result.Length - 1
Console.Write("'{0}'", result(ctr))
If ctr < result.Length - 1 Then Console.Write(", ")
Next
Console.WriteLine()
End Sub
End Module
輸出:
, '1234', '5678', '9012', ''
示例2: Example
' 導入命名空間
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim input As String = "plum-pear"
Dim pattern As String = "(-)"
Dim substrings() As String = Regex.Split(input, pattern) ' Split on hyphens.
For Each match As String In substrings
Console.WriteLine("'{0}'", match)
Next
End Sub
End Module
' The method writes the following to the console:
' 'plum'
' '-'
' 'pear'
示例3: Example
' 導入命名空間
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim input As String = "07/14/2007"
Dim pattern As String = "(-)|(/)"
For Each result As String In Regex.Split(input, pattern)
Console.WriteLine("'{0}'", result)
Next
End Sub
End Module
' In .NET 1.0 and 1.1, the method returns an array of
' 3 elements, as follows:
' '07'
' '14'
' '2007'
'
' In .NET 2.0 and later, the method returns an array of
' 5 elements, as follows:
' '07'
' '/'
' '14'
' '/'
' '2007'
示例4: Example
' 導入命名空間
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim pattern As String = "[a-z]+"
Dim input As String = "Abc1234Def5678Ghi9012Jklm"
Dim result() As String = Regex.Split(input, pattern,
RegexOptions.IgnoreCase)
For ctr As Integer = 0 To result.Length - 1
Console.Write("'{0}'", result(ctr))
If ctr < result.Length - 1 Then Console.Write(", ")
Next
Console.WriteLine()
End Sub
End Module
輸出:
, '1234', '5678', '9012', ''
示例5: Example
' 導入命名空間
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim pattern As String = "\d+"
Dim rgx As New Regex(pattern)
Dim input As String = "123ABCDE456FGHIJ789KLMNO012PQRST"
Dim m As Match = rgx.Match(input)
If m.Success Then
Dim startAt As Integer = m.Index
Dim result() As String = rgx.Split(input, 3, startAt)
For ctr As Integer = 0 To result.Length - 1
Console.Write("'{0}'", result(ctr))
If ctr < result.Length - 1 Then Console.Write(", ")
Next
Console.WriteLine()
End If
End Sub
End Module
輸出:
, 'ABCDE', 'FGHIJKL789MNOPQ012'
示例6: Example
' 導入命名空間
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim pattern As String = "(-)"
Dim input As String = "apple-apricot-plum-pear-pomegranate-pineapple-peach"
Dim regex As Regex = New Regex(pattern)
' Split on hyphens from 15th character on
Dim substrings() As String = regex.Split(input, 4, 15)
For Each match As String In substrings
Console.WriteLine("'{0}'", match)
Next
End Sub
End Module
輸出:
apple-apricot-plum' -' pear' -' pomegranate' -' pineapple-peach'
示例7: Example
' 導入命名空間
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim pattern As String = "(-)|([|])" ' possible delimiters found in string
Dim input As String = "apple|apricot|plum|pear|pomegranate|pineapple|peach"
Dim regex As Regex = New Regex(pattern)
' Split on delimiters from 15th character on
Dim substrings() As String = regex.Split(input, 4, 15)
For Each match As String In substrings
Console.WriteLine("'{0}'", match)
Next
End Sub
End Module
' In .NET 2.0, the method returns an array of
' 7 elements, as follows:
' apple|apricot|plum'
' '|'
' 'pear'
' '|'
' 'pomegranate'
' '|'
' 'pineapple|peach'
' In .NET 1.0 and 1.1, the method returns an array of
' 4 elements, as follows:
' 'apple|apricot|plum'
' 'pear'
' 'pomegranate'
' 'pineapple|peach'
示例8: Example
' 導入命名空間
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim input As String = "characters"
Dim regex As New Regex("")
Dim substrings() As String = regex.Split(input, input.Length, _
input.IndexOf("a"))
Console.Write("{")
For ctr As Integer = 0 to substrings.Length - 1
Console.Write(substrings(ctr))
If ctr < substrings.Length - 1 Then Console.Write(", ")
Next
Console.WriteLine("}")
End Sub
End Module
輸出:
{, c, h, a, r, a, c, t, e, rs}
示例9: Example
' 導入命名空間
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim pattern As String = "\d+"
Dim rgx As New Regex(pattern)
Dim input As String = "123ABCDE456FGHIJKL789MNOPQ012"
Dim result() As String = rgx.Split(input, 3)
For ctr As Integer = 0 To result.Length - 1
Console.Write("'{0}'", result(ctr))
If ctr < result.Length - 1 Then Console.Write(", ")
Next
Console.WriteLine()
End Sub
End Module
輸出:
, 'ABCDE', 'FGHIJKL789MNOPQ012'
示例10: Example
' 導入命名空間
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim pattern As String = "(-)"
Dim input As String = "apple-apricot-plum-pear-banana"
Dim regex As Regex = New Regex(pattern) ' Split on hyphens.
Dim substrings() As String = regex.Split(input, 4)
For Each match As String In substrings
Console.WriteLine("'{0}'", match)
Next
End Sub
End Module
輸出:
apple' -' apricot' -' plum' -' pear-banana'
示例11: Example
' 導入命名空間
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim input As String = "07/14/2007"
Dim pattern As String = "(-)|(/)"
Dim regex As Regex = New Regex(pattern)
For Each result As String In regex.Split(input, 2)
Console.WriteLine("'{0}'", result)
Next
End Sub
End Module
' In .NET 1.0 and 1.1, the method returns an array of
' 2 elements, as follows:
' '07'
' '14/2007'
'
' In .NET 2.0 and later, the method returns an array of
' 3 elements, as follows:
' '07'
' '/'
' '14/2007'
示例12: Example
' 導入命名空間
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim input As String = "characters"
Dim regex As New Regex("")
Dim substrings() As String = regex.Split(input, input.Length)
Console.Write("{")
For ctr As Integer = 0 to substrings.Length - 1
Console.Write(substrings(ctr))
if ctr < substrings.Length - 1 Then Console.Write(", ")
Next
Console.WriteLine("}")
End Sub
End Module
輸出:
{, c, h, a, r, a, c, t, e, rs}
示例13: RegexSplit
' 導入命名空間
Imports System.Text.RegularExpressions
Module RegexSplit
Public Sub Main()
Dim regex As Regex = New Regex("-") ' Split on hyphens.
Dim substrings() As String = regex.Split("plum--pear")
For Each match As String In substrings
Console.WriteLine("'{0}'", match)
Next
End Sub
End Module
輸出:
plum' pear'
示例14: Example
' 導入命名空間
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim pattern As String = "\d+"
Dim rgx As New Regex(pattern)
Dim input As String = "123ABCDE456FGHIJKL789MNOPQ012"
Dim result() As String = rgx.Split(input)
For ctr As Integer = 0 To result.Length - 1
Console.Write("'{0}'", result(ctr))
If ctr < result.Length - 1 Then Console.Write(", ")
Next
Console.WriteLine()
End Sub
End Module
輸出:
, 'ABCDE', 'FGHIJKL', 'MNOPQ', ''
示例15: Example
' 導入命名空間
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim regex As Regex = New Regex("(-)") ' Split on hyphens.
Dim substrings() As String = regex.Split("plum-pear")
For Each match As String In substrings
Console.WriteLine("'{0}'", match)
Next
End Sub
End Module
輸出:
plum' -' pear'