I don't know of any built in support for it, but you can use the charAt()
property of strings, and associative arrays to do the following:
var charCounter:Object = new Object();
var str:String = "ABDDEEDDC";
var maxCount:int = 0;
var maxChar:String = "";
for(var i = 0; i < str.length; i++) {
// Must make sure the associate array is initialised!
if(charCounter.hasOwnProperty(str.charAt(i)) {
charCounter[str.charAt(i)]++;
} else {
charCounter[str.charAt(i)] = 1;
}
if(charCounter[str.charAt(i)] > maxCount) {
maxCount = charCounter[str.charAt(i)];
maxChar = str.charAt(i);
}
}
At the end of this the character should be in maxChar, and the number of times it appears in maxCount.
charAt()
.
Associative Arrays.
(Sidenote: I believe that instead of charCounter.hasOwnProperty(str.charAt(i))
you can use str.charAt(i) in charCounter
, but I've not tested it.)