Advertisement
NAK

Character Counter

NAK
May 29th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.86 KB | None | 0 0
  1.         Dim YourString As String = TextBox1.Text '
  2.         ' strip out the spaces
  3.         YourString = System.Text.RegularExpressions.Regex.Replace(YourString, " ", "")
  4.         While YourString.Length() > 0 ' loop round untill we run out of characters
  5.             Dim pattern As String = "\" + YourString.Substring(0, 1) ' take the first character of YourString
  6.             Dim ex As New System.Text.RegularExpressions.Regex(pattern)
  7.             Dim m As System.Text.RegularExpressions.MatchCollection
  8.             m = ex.Matches(YourString) ' get the number of matches
  9.             Message = Message + String.Format("{0}*{1}'s ", m.Count.ToString(), YourString.Substring(0, 1)) ' format the message
  10.             YourString = System.Text.RegularExpressions.Regex.Replace(YourString, pattern, "") ' remove the character
  11.         End While
  12.         TextBox2.Text = Message
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement