本文整理汇总了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'