### 5.2.4 Extracting portions of a string

The left and right commands find the left and right parts of a string. (See Section 8.2.3, Section 6.5.1, Section 6.6.2, Section 6.3.6, Section 9.3.4, Section 9.3.5, Section 28.2.8 and Section 28.2.9 for other uses of left and right.)

- left takes two arguments:
  - str, a string.
  - n, a non-negative integer.
- left(str,n) returns the first n characters of the string str.
- right takes two arguments:
  - str, a string.
  - n, a non-negative integer.
- right(str,n) returns the last n characters of the string str.

The head command finds the first character of a string.

- head takes str, a string.
- head(str) returns the first character of the string str.

The mid command finds a selected part from the middle of a string.

- mid takes three arguments:
  - str, a string.
  - p, an integer for the starting index of the result.
  - q, an integer q for the length of the string.
- mid(str,p,q) returns the part of the string str starting with the character at index p with length q. (Remember that the first index is 0 in Xcas mode.)

The tail command removes the first character of a string.

- tail takes str, a string.
- tail(str) returns the string str without its first character.

#### Examples

left("hello",3)

“hel” |  |  |  |  |  |  |  |  |  |

right("hello",4)

“ello” |  |  |  |  |  |  |  |  |  |

head("Hello")

“H” |  |  |  |  |  |  |  |  |  |

mid("Hello",1,3)

“ell” |  |  |  |  |  |  |  |  |  |

tail("Hello")

“ello” |  |  |  |  |  |  |  |  |  |