cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MaxDonen
Level: Powered On

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
Super User

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

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

 

 

View solution in original post

Community Support Team
Community Support Team

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

Hi @MaxDonen ,

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
Super User

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

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

 

 

View solution in original post

Community Support Team
Community Support Team

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

Hi @MaxDonen ,

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

MaxDonen
Level: Powered On

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

<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
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (5,110)