Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleUse regular expressions to replace text in a string in VB .NET
DescriptionThis example shows how to use regular expressions to replace text in a string in VB .NET. It uses the Regex class's Replace method to make the replacements.
Keywordsregular expression, string, parsing, parse, replace
CategoriesStrings, Algorithms
 
The program creates a Regex object, passing its constructor a regular expression pattern that will identify text to replace. It calls the object's Replace method, passing it the replacement pattern.
 
Private Sub btnGo_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnGo.Click
    Dim reg_exp As New Regex(txtPattern.Text)
    lblResult.Text = reg_exp.Replace(Me.txtTestString.Text, _
        txtReplacementPattern.Text)
End Sub
 
In this example, the search pattern is "[aeiouAEIOU]" and the replacement pattern is "." so the program replaces all instances of vowels with periods.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated