Skip to main content

Notifications

Community site session details
Power Apps - Building Power Apps
Answered

Word count for textbox

Like (1) ShareShare
ReportReport
Posted on 4 Mar 2021 16:49:31 by 249

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

Categories:
  • CrimsonCrayon Profile Picture
    68 on 17 Feb 2023 at 18:51:47
    Re: Word count for textbox

    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?

  • Shaheer Ahmad Profile Picture
    2,194 Super User 2025 Season 1 on 25 Jul 2022 at 09:15:34
    Re: Word count for textbox

    Thanks a lot brother

  • timl Profile Picture
    34,988 Super User 2025 Season 1 on 25 Jul 2022 at 08:59:09
    Re: Word count for textbox

    @ShaheerAhmad 

    The Len function returns the number of letters/characters.

    Len(TextInput1.Text)

     

  • Shaheer Ahmad Profile Picture
    2,194 Super User 2025 Season 1 on 24 Jul 2022 at 13:32:16
    Re: Word count for textbox

    Can you please tell me a solution to get the number of letters instead of words?

  • techtudoor Profile Picture
    249 on 04 Mar 2021 at 17:30:10
    Re: Word count for textbox

    Thanks Randy. That explanation was great. It now makes sense. Greatly appreciate you taking time to explain this. 

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 04 Mar 2021 at 17:13:01
    Re: Word count for textbox

    @techtudoor 

    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.

     

  • techtudoor Profile Picture
    249 on 04 Mar 2021 at 17:05:35
    Re: Word count for textbox

    @timl 

     

    Thank you, I will keep this in mind if I need to do this for a single line of text input. 

  • techtudoor Profile Picture
    249 on 04 Mar 2021 at 17:04:36
    Re: Word count for textbox

    @RandyHayes 

     

      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

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 04 Mar 2021 at 17:01:35
    Re: Word count for textbox

    @techtudoor 

    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.

     

  • timl Profile Picture
    34,988 Super User 2025 Season 1 on 04 Mar 2021 at 16:58:51
    Re: Word count for textbox

    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, " "))

     

    timl_0-1614877122393.png

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Building Power Apps

#1
MS.Ragavendar Profile Picture

MS.Ragavendar 20

#2
BCBuizer Profile Picture

BCBuizer 10 Super User 2025 Season 1

#2
LC-26081402-0 Profile Picture

LC-26081402-0 10

Overall leaderboard
Loading started
Loading started