substring -- extract part of a string

Synopsis

• Usage:
substring(i, s)
substring(i, n, s)
substring(s, i, n)
substring(s, i)
substring((i, n), s)
• Inputs:
• i, an integer, starting index of substring
• n, an integer, length of substring
• s,
• Outputs:

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.```

• lines -- split a string into lines
• separate -- split a string into substrings
• separateRegexp -- split a string into substrings, using a regular expression to define the separators
• strings and nets -- an overview of strings and nets in Macaulay2
• regular expressions -- syntax for regular expressions inside Macaulay2

Ways to use substring :

• substring(Sequence,String)
• substring(String,ZZ)
• substring(String,ZZ,ZZ)
• substring(ZZ,String)
• substring(ZZ,ZZ,String)