Re: Testing a String for 'most' Capitalised

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux