Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
ASP.NET: Filter words
From Wiki
Summary: An example of how we can filter certain words in a string and mask them by replacing them with an asterisk.
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- ' Declarations
- Dim arrWords As New ArrayList
- Dim strArticle As String = "This is one sample string that three people wrote"
- ' Populate the array list with the words we want to replace
- arrWords.Add("one")
- arrWords.Add("two")
- arrWords.Add("three")
- ' Loop through the array list and replace each found word with *'s
- Dim IEnum As IEnumerator = arrWords.GetEnumerator
- While IEnum.MoveNext
- strArticle = strArticle.ToLower.Replace(IEnum.Current, New String("*", IEnum.Current.ToString.Length))
- End While
- ' Show the resulting string
- Label1.Text = strArticle
- End Sub
Output:
- This is *** sample string that ***** people wrote
This Hack is part of the ASP.NET Hacks collection



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.