Re: Detecting case change?

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

 



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)
	}
}

--
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