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


