|
Posted by Robert Cummings on 07/22/05 01:38
On Thu, 2005-07-21 at 18:30, Philip Hallstrom wrote:
> > 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);
Just in case you're not aware... you can loop over a strings characters
using the string index notation:
$length = strlen( $word );
for( $i = 1; $i < $lengthl $i++ )
{
$a = $word{$i - 1};
$b = $word{$i};
}
Cheers,
Rob.
--
..------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
Navigation:
[Reply to this message]
|