Macaulay2 » Documentation
Packages » Macaulay2Doc > The Macaulay2 language > strings and nets > substring
next | previous | forward | backward | up | index | toc

substring -- extract part of a string

Synopsis

Description

The expressions substring(i, n, s), substring(s, i, n), and substring((i, n), s) all return the substring that starts at index i and has n characters.

In other words, if $s=s_0s_1s_2\ldots s_k$, then the substring returned is $s_i s_{i+1}\ldots s_{i+n-1}$.

Indices begin at zero, and a negative index is counted from the end of the string. Requests for out-of-bound character positions are silently ignored.

i1 : s = "I love computing Groebner bases in Macaulay2.";
i2 : substring(0, 5, s)

o2 = I lov
i3 : substring(s, -10, 5)

o3 = Macau
i4 : substring(s, 100, 5)

o4 = 
i5 : substring((3, 10), s)

o5 = ove comput

The expressions substring(i, s) and substring(s, i) return the substring that starts at index i and continues to the end of the string.

In other words, if $s=s_0s_1s_2\ldots s_k$, then the substring returned is $s_i s_{i+1}\ldots s_k$.

i6 : substring(3, s)

o6 = ove computing Groebner bases in Macaulay2.
i7 : substring(s, -10)

o7 = Macaulay2.

See also

Ways to use substring :

For the programmer

The object substring is a compiled function.