Using Regex method Replace:First 3 digits replaced
Imports System.Text.RegularExpressions
Imports System
Public Class MainClass
Shared Sub Main()
Dim testString1 As String = "This sentence ends in 5 stars *****"
Dim testString2 As String = "1, 2, 3, 4, 5, 6, 7, 8"
Dim testRegex1 As Regex = New Regex("stars")
Dim testRegex2 As Regex = New Regex("\d")
Console.WriteLine("Original String 2" & _
vbTab & vbTab & vbTab & testString2)
Console.WriteLine("First 3 digits replaced by " & _
"""digit""" & vbTab & _
testRegex2.Replace(testString2, "digit", 3))
End Sub ' Main
End Class
Related examples in the same category