Thanks Dermot and erez.schatz

I got it ~
On Tue, Dec 8, 2009 at 4:59 PM, Erez Schatz <moonb...@gmail.com> wrote:

> 2009/12/8 Majian <jian...@gmail.com>:
> > my $s = "The black cat jumped from the green tree";
> > print index $s, "e", 3  ####The result is 18
>
> It's slightly confusing, but if you get the idea behind it, it's
> actually very simple:
>
> counting from 0, the string "The black cat jumped from the green tree"
> has an 'e' at the 2nd position, then at the 18th position. You
> specified 3 as the start position, so index ignores the e at the 2nd
> position, and returns the first 'e' it finds, at the 18th position.
>
> I'm assuming you expected 14, however, the real index is better, since
> in future reference to the string, you don't need to recall where you
> started the original index count, then redo some calculations etc.
> whenever you need to refer to that 'e' all you now need is that it's
> actual position in the string
>
> --
> Erez
>
> "The government forgets that George Orwell's 1984 was a warning, and
> not a blueprint"
> http://www.nonviolent-conflict.org/ -- http://www.whyweprotest.org/
>

Reply via email to