Posted by "Chris Boget" on 10/10/05 15:52
> Image that there could be a string
> fred
> Fred
> FRED
> First of all I need to know that these are same which I can do with
> strtolower, but how could I tell
> that 'FRED' is 'most captilised?
Iterate through the string and count the number of capitalised letters.
You can do something like this (untested pseudocode)
$myStr = "Fred";
$numOfCapLetters = 0;
$curLetter = '';
for( $i = 0; $i <= strlen( $myStr ); $i++ ) {
$curLetter = $myStr{$i};
if( strtoupper( $curLetter ) == $curLetter ) {
$numOfCapLetters++;
}
}
then just compare the $numOfCapLetters for each string.
thnx,
Chris
Navigation:
[Reply to this message]
|