Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
SureshUK
Contributor II
Contributor II

Finding maximum occurrence of a character in a string

Hi,

Is there a way of finding maximum occurrence of a character in a given string?

Example: In the string "RAGR", "R" has occurred twice.

The string will always have just one character occurring multiple times and there won't be any stalemate.

Thanks.

1 Solution

Accepted Solutions
sunny_talwar

Try this

=Left(Trim(Concat(DISTINCT Mid(Field, ValueLoop(1, 100), 1), '', -SubStringCount(Field, Mid(Field, ValueLoop(1, 100), 1)))), 1)


Capture.PNG

View solution in original post

13 Replies
richard_chilvers
Specialist
Specialist

Hi

Is the string always 4 characters in length ?

darrell_tobin
Creator
Creator

Hi Raj

Substringcount function see example below:

 

HospitalName=substringcount([HospitalName], 'I')
Aberdeen Royal Infirmary1
Aberdeen Royal Infirmary (T3)1
Addenbrookes (T3)0

Please mark and helpful and correct if so...

Thanks

sunny_talwar

Is this something you need in script or front end?

SureshUK
Contributor II
Contributor II
Author

Need not be 4 digit and it can vary

SureshUK
Contributor II
Contributor II
Author

In the front end

SureshUK
Contributor II
Contributor II
Author

I get this but how do I find out the maximum with out many IF conditions?

sunny_talwar

Try this

=Left(Trim(Concat(DISTINCT Mid(Field, ValueLoop(1, 100), 1), '', -SubStringCount(Field, Mid(Field, ValueLoop(1, 100), 1)))), 1)


Capture.PNG

SureshUK
Contributor II
Contributor II
Author

This looks to me working! Thanks for your help.

SureshUK
Contributor II
Contributor II
Author

Hi Sunny,

I have an additional requirement on this. When two characters have same frequency, I would like it to be sorted by descending.

Example: for the value 44223, I would like the outcome to be 4 not 2.