[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: Wed, 19 Nov 2014 17:24:22 +0000

Hi Steffen,

> > >     Replace the string named xx with the substring defined by
> > >     the indices n1 and n2.
> > 
> > Maybe:
> > 
> >   Replace the string named xx with its substring beginning with
> >   the zero-based index n1 and ending with index n2, inclusively.
> Inclusive index n2 of the _resulting substring_, please.

But n2 is relative to the start of the original value of xx.

    $ nroff
    .ds s abcdefghij
    .substring s 3 5
    .tm \*s

The full documentation of .substring wasn't originally given.

    -- Request: .substring str n1 [n2]
        Replace the string named STR with the substring defined by the
        indices N1 and N2.  The first character in the string has index 0.
        If N2 is omitted, it is taken to be equal to the string's length.
        If the index value N1 or N2 is negative, it is counted from the
        end of the string, going backwards: The last character has
        index -1, the character before the last character has index -2,

            .ds xxx abcdefgh
            .substring xxx 1 -4
                => bcde

I think the only thing it doesn't cover is what happens if characters
off the end of the original string are requested, e.g. are spaces
delivered?  The answer is no, the requested characters are truncated to
the end of the source.

Note, `3 6' and `6 3' give the same result;  N1 and N2 are inclusive
indices in either order.

Cheers, Ralph.

reply via email to

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