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

Re: [MacPerl] working with strings



At 09:42 -0800 1/22/99, Adam Bridge wrote:
> The way I'd think to do it in a traditional language is to find the last
> character that isn't whitespace to get the real length of the name, find
>the
> comma, take the characters up to the comma as the last name and the rest,
>save
> the leading space, as the first name.
>
> But there doesn't seem to be that sort of addressability inside strings.

Sure, there is.  With regular expressions (as shown previously); regular
expressions are deep juju. With split (if you just want to break things up;
as shown previously; your comma separated data is a natural for split ;-)
and with index, which returns the position of the first occurance of a
substring within a string.  An optional argument tells index where to start
looking.

It's cohort, rindex, returns the position of the _last_ occurence of a
given substring in a given string.

TMTOWTDI, after all...

At 10:08 -0800 1/22/99, Chris Nandor wrote:
> But there are many other ways.  You could use substr and index and length,
> but I would not recommend it.

For this particular application, no, probably not :-) But if that's what
you're used to, then, maybe...
---
      |\      _,,,---,,_       Vicki Brown <vlb@cfcl.com>
ZZZzz /,`.-'`'    -.  ;-;;,_   Journeyman Sourceror: Scripts & Philtres
     |,4-  ) )-,_. ,\ (  `'-'  P.O. Box 1269  San Bruno  CA  94066
    '---''(_/--'  `-'\_)       http://www.cfcl.com/~vlb  www.ptf.com/macperl

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch