Can someone please tell me how I can calculate the amount of words as the end-user is typing in a textbox and the amount to appear in a label? Thanks in advance.
Printable View
Can someone please tell me how I can calculate the amount of words as the end-user is typing in a textbox and the amount to appear in a label? Thanks in advance.
Probably not the most elegant solution, and you should almost definitely be using a stringbuilder if the string involved is any great length, but if you add something like this code to the textchanged event of teh text box, it will be a good start...
VB Code:
Dim strText As String strText = txtWords.Text.Replace(",", " ") strText = strText.Replace(".", " ") strText = strText.Replace(";", " ") Dim strWords() As String = strText.ToString.Split(" "c) Dim intWords As Int32 For intWord As Int32 = 0 To strWords.Length - 1 If strWords(intWord).Trim <> "" Then intWords += 1 Next lblWords.Text="Count:" & intWords.ToString