cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Return total number of a given character/string from another string

I cannot find a way to do this, and it seems so simple!

 

Eg, find number of 's' in 'snakes' or '.' in "www.hotmail.com"

 

Apologies if this has been asked elsewhere, but I can't find anything after lengthy searching.

 

Thanks.

2 ACCEPTED SOLUTIONS

Accepted Solutions
Super User III
Super User III

Hi @Anonymous 

You can call the MatchAll function to search for a character in string. MatchAll returns a table for all matches that are found. The CountRows function will then provide a count of results like so:

CountRows(MatchAll("snakes", "s"))

Note that the MatchAll function accepts a search pattern in the form of a regular expression. The period symbol is a special character so in your hotmail example, you would need to escape this with a \ symbol.

CountRows(MatchAll("www.hotmail.com", "\."))

 

 

View solution in original post

Community Support
Community Support

Hi @Anonymous ,

Do you want to calculate the total number of a given character/string within another string?

 

Based on the needs that you mentioned, I think the MatchAll function could achieve your needs. I have made a test on my side, please take a try with the following workaround:

Add a Label in your app, set the Text property to following:

CountRows(MatchAll("snakes", "s", MatchOptions.Contains))
CountRows(MatchAll("www.hotmail.com", "\.", MatchOptions.Contains))

Please consider take a try with above solution, check if the issue is solved.

 

More details about the MatchAll function, please check the following article:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-ismatch

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Super User III
Super User III

Hi @Anonymous 

You can call the MatchAll function to search for a character in string. MatchAll returns a table for all matches that are found. The CountRows function will then provide a count of results like so:

CountRows(MatchAll("snakes", "s"))

Note that the MatchAll function accepts a search pattern in the form of a regular expression. The period symbol is a special character so in your hotmail example, you would need to escape this with a \ symbol.

CountRows(MatchAll("www.hotmail.com", "\."))

 

 

View solution in original post

Community Support
Community Support

Hi @Anonymous ,

Do you want to calculate the total number of a given character/string within another string?

 

Based on the needs that you mentioned, I think the MatchAll function could achieve your needs. I have made a test on my side, please take a try with the following workaround:

Add a Label in your app, set the Text property to following:

CountRows(MatchAll("snakes", "s", MatchOptions.Contains))
CountRows(MatchAll("www.hotmail.com", "\.", MatchOptions.Contains))

Please consider take a try with above solution, check if the issue is solved.

 

More details about the MatchAll function, please check the following article:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-ismatch

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Anonymous
Not applicable

<quote>

Hi @MaxDonen 

You can call the MatchAll function to search for a character in string. MatchAll returns a table for all matches that are found. The CountRows function will then provide a count of results like so:

CountRows(MatchAll("snakes", "s"))

Note that the MatchAll function accepts a search pattern in the form of a regular expression. The period symbol is a special character so in your hotmail example, you would need to escape this with a \ symbol.

CountRows(MatchAll("www.hotmail.com", "\."))

 

</quote>

Brilliant-exactly what I was looking for. Thank you.

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Top Solution Authors
Top Kudoed Authors
Users online (57,425)