So I am building an App that has a multi-line textbox that needs to have a limit of x amount of words. I can count characters, but not sure how to do a word count to show the user the amount of words they have typed or have left.
Any suggestions greatly appreciated
I used this solution and it has worked great ... but I had one user hit the carriage return a few times after entering their input and the function seemed to count these blank rows as well. Is there anyway around this?
Thanks a lot brother
Can you please tell me a solution to get the number of letters instead of words?
Thanks Randy. That explanation was great. It now makes sense. Greatly appreciate you taking time to explain this.
This is a regular expression. It essentially says - match any thing that is not a white space (\S) and ends with either zero or more (?) a whitespace (/s) or zero or more (?) a newline (\n)
So this text:
The quick
brown fox
Is :
\S\S\S\s\S\S\S\S\S\n\S\S\S\S\S\s\S\S\S\s
T h e q u i c k b r o w n f o x
The regular expression "\S*(\s|\n?)" says to match all of the \S's that end with \s or \n
The MatchAll function returns a table. The table has records with two columns, the FullMatch and the character location. We only care about the number of full matches and we first filter that to make sure we have no blank full matches, then count the number of rows.
That worked great, Thank you so much. Now to show my ignorance. Could you explain what "\S*(\s|\n?)" is doing? This way I can understand what I am doing rather than just typing it in.
Thank you
Yep, @timl 's solution will work too, but you might have issue with that for a mult-line text as words in those that are at the end of a line are typically ended with a char(10). The match function expression will account for that.
Hi @techtudoor
I'd suggest pretty much the same as Randy. I usually just split the text by the space character and do a count of the result.
CountRows(Split(TextInput2.Text, " "))
MS.Ragavendar
20
BCBuizer
10
Super User 2025 Season 1
LC-26081402-0
10