---
name: "Prelude.substr"
section: "3kaya"
platform: "linux"
package: "kaya"
version: "0.4.4-6.2"
release: "Debian 8 (Jessie)"
platforms: ["linux"]
url: "https://new.carta.tech/Prelude.substr"
---

# Prelude.substr(3kaya)

Return a substring.

## NAME

Prelude::substr - Return a substring.

## SYNOPSIS

**String substr(** *String x, Int i, Int len* **)**

## ARGUMENTS

**x** The original string

**i** The starting index

**len** The substring length

## DESCRIPTION

Starting at character *i* , return the *len* characters long substring. Throws an Exception if *len* is negative, or if *i* is out-of-bounds. In Kaya 0.2.4 and earlier, an Exception was also thrown if *len* was zero. The empty string is now returned in this case.

If the starting index is negative, then it will be counted in characters from the end of the string.

-

   x = "abcdef";\
    s = substr(x,0,2); // "ab"\
    s = substr(x,4,1); // "e"\
    s = substr(x,3,10); // "def" ( *len*\
    truncated)\
    s = substr(x,-4,2); // "cd"

## AUTHORS

Kaya standard library by Edwin Brady, Chris Morris and others (kaya@kayalang.org). For further information see http://kayalang.org/

## LICENSE

The Kaya standard library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (version 2.1 or any later version) as published by the Free Software Foundation.
