# 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=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.