I don't think this algorithm is too "sexy". It's very inefficient. You use a for loop in a for loop which runs through the text again and again and you do other unnecesseary operations.
You can do the counting part with one for loop and a Map. You run through the text with the loop and for every character you have 2 options:
1, Character not in the map, you put it into the map with a value of 1.
2, The Map contains the chraracter: You increment the stored value by one.
From the map you know the:
-number of different characters
-which are these characters
-how many of them you have
So you have all the necesseary information.
I hope it helps.
alfonz jan frithz
Joined: Apr 20, 2009
thanks for the solution... its cool man...
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com