[Top][All Lists]

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

Re: [Groff] Question about .substring

From: Ralph Corderoy
Subject: Re: [Groff] Question about .substring
Date: Thu, 20 Nov 2014 13:10:36 +0000

Hi Ingo,

> > for example, and without introducing lengthy calculations
> Lengthy?  If you have the offset and length (> 0), all it takes is one
> addition and decrementing by one.

I think his point is given string s of `abcdefghij', one wants the
substring starting at index 2, `c', of length 0, 1, or 2.  `2 2' gives
`c', `2 3' `cd'.  `2 1' is swapped to `1 2' giving `bc'.  There's no
second parameter that gives an empty string, unlike the [startindex,
endindex) interval where endindex is exclusive, e.g. Python.

    $ python -c 'print "abcdefghij"[2:2]' | od -c
    0000000  \n

So that means testing the length number register to see if it's zero and
defining the string to be empty if it is, or doing the maths for
.substring otherwise.

Obviously, ;-)
the new expression syntax would have a substring function that returns
rather than modifies and uses the normal [) interval.

Cheers, Ralph.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]