You are here: Re: [PHP] Detecting case change? « PHP « IT news, forums, messages
Re: [PHP] Detecting case change?

Posted by Philip Hallstrom on 07/22/05 01:30

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация