On Mon, 4 Jun 2001, Nathaniel Mallet <[EMAIL PROTECTED]> wrote,

> Date: Mon, 4 Jun 2001 21:06:43 -0400
> From: Nathaniel Mallet <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: Substring retrieval
>
> Hi,
>
>     I'm trying to retrieve a substring from a string, but I'm not sure
>     exactly where and how big that substring is. The substring is
>     delimited by a start and end special character. It was suggested to
>     me to write two regular expression, one that would match everything
>     up to and including the start special character, and one to match
>     everything following and including the end special character, and
>     replacing the matches with nothing.
>
>     I thought finding the location of the start and end special
>     characters, then calling substr().
>
> And so I have to questions:
> 1 - How would I find the index for a particular character in a string?

Using index() function.  Now, doesn't it suprise you?

    perldoc -f index


> 2 - What's the best method, everything considered (simplicity,
> performance, etc).

-   how many times does the substring you want to retrieve occur
    in the string?  Exactly once? Can be more?
-   Are the start and end special characters just the same?

Regular expression is the common way to solve this, but you could also
use split() or combination of substr/index.

__END__
s.a.n
-- 
Hasanuddin Tamir: [EMAIL PROTECTED] - Trabas: www.trabas.com

Reply via email to