next | previous | forward | backward | up | top | index | toc | Macaulay2 web site
Macaulay2Doc :: substring

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=s0s1s2...sk, then the substring returned is si si+1...si+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=s0s1s2...sk, then the substring returned is si si+1...sk.

i6 : substring(3, s)

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

o7 = Macaulay2.

See also

Ways to use substring :