Re: Detecting case change?

From: Date: Thu, 21 Jul 2005 22:30:55 +0000
Subject: Re: Detecting case change?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-219159@lists.php.net to get a copy of this message
Hi- how can I find the character postion in a string right before the first case change? Is there a function out there that already does this? E.g. passing the string "WebApplication" to this function would return the number 2. Thanks for any input.
I can't think of a function that does this, but something like this should work. Not sure how efficient it is to constantly call substr() on the string. Might be better to split it up into an array to start with. Or there might be a "get character at" function, but I don't see it right now... $word = "WebApplication"; $length = strlen($word); for ( $i = 1; $i < $length; $i++ ) { $a = substr($word, $i - 1, 1); $b = substr($word, $i, 1); if ( ($a >= 'a' && $a <= 'z' && $b >= 'A' && $b <= 'Z') || ($a >= 'A' && $a <= 'Z' && $b >= 'a' && $b <= 'z') ) { // case change at $i which for $word would equal 1 (not 2) } }

« previous php.general (#219159) next »