Ashley Sanders writes:
> > Where <start1> is a one-based character-count (0 is illegal) and the
> > :<length> is optional. If <length> is negative, it counts backwards
> > from the end of the string. So:
>
> > No negative numbers, no special cases.
> >
> > Agreed?
>
> Sorry, but no. What you're proposing does have negative numbers and a
> negative numbers is a special case. If it wasn't a special case you
> wouldn't have felt the need to add "If <length> is negative, ..."
Sorry, that's a typo. I adapted my older version of the proposal and
didn't snip out all the parts I meant to.
> If you want a substring that works from the end of the string
> rather than the beginning have both "substring" and "r_substring".
> Then you'd have no need of negative numbers and special cases.
I dunno now. Maybe the way to go is just to adopt Perl's substr()
arguments and have done. From the manual, with the Perl-only details
removed:
substr EXPR,OFFSET,LENGTH
substr EXPR,OFFSET
Extracts a substring out of EXPR and returns it.
First character is at offset 0. If OFFSET is
negative, starts that far from the end of the string.
If LENGTH is omitted, returns everything to the end of
the string. If LENGTH is negative, leaves that many
characters off the end of the string.
If OFFSET and LENGTH specify a substring that is
partly outside the string, only the part within the
string is returned.
That sounds very straightforward and very flexible.
_/|_ ___________________________________________________________________
/o ) \/ Mike Taylor <[log in to unmask]> http://www.miketaylor.org.uk
)_v__/\ "Do you WAAAAANT to come back to my place, bouncy-bouncy?" --
Monty Python's Flying Circus.
|