XLISP subseq

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference

# subseq

Type: | - | function (subr)
Source: | - | xlstr.c

## Syntax

(subseq string start [end])
  string - a string expression
  start - an integer expression
  end - an integer expression
  returns - the substring between start and end

## Description

The 'subseq' function extracts a substring from 'string' starting with the 'start' offset and ending with the 'end' offset. The 'start' offset has a origin or 0. The substring is returned.

## Examples

    (subseq "12345678" 0)     ; returns "12345678"
    (subseq "12345678" 2)     ; returns "345678"
    (subseq "12345678" 2 4)   ; returns "34"
    (subseq "1234" 3)         ; returns "4"

    (subseq "1234" 4)         ; returns ""
    (subseq "1234" 4 2)       ; returns ""
    (subseq "1234" 5)         ; error: string index out of bounds - 5

Common Lisp: The 'subseq' function in Common Lisp is intended to return a portion of a sequence, a sub-sequence. This function operates on lists and vectors [one-dimensional arrays of data], basically ordered data. Strings are just one of the valid types operated on by 'subseq' in Common Lisp. The XLISP 'subseq' function only operates on strings.

See the subseq function in the XLISP 2.0 manual.

Back to Top

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference