JanetDocsPlaygroundI'm feeling luckyGitHub sign in

string/slice



    cfunction
    src/core/string.c on line 179, column 1

    (string/slice bytes &opt start end)

    Returns a substring from a byte sequence. The substring is from 
    index `start` inclusive to index `end`, exclusive. All indexing is 
    from 0. `start` and `end` can also be negative to indicate indexing 
    from the end of the string. Note that index -1 is synonymous with 
    index `(length bytes)` to allow a full negative slice range.


1 exampleSign in to add an example
Loading...
(string/slice "hello")    # => "hello"

(string/slice "hello" 0)  # => "hello"
(string/slice "hello" 1)  # => "ello"
(string/slice "hello" 4)  # => "o"
(string/slice "hello" 5)  # => ""

(string/slice "hello" -1)  # => ""
(string/slice "hello" -2)  # => "o"
(string/slice "hello" -5)  # => "ello"
(string/slice "hello" -6)  # => "hello"

(string/slice "hello" 1 1)  # => ""
(string/slice "hello" 1 2)  # => "e"
(string/slice "hello" 1 5)  # => "ello"

(string/slice "hello" -5 -4)  # => "e"
(string/slice "hello" -6 -4)  # => "he"

(string/slice "hello"  2  1)  # => ""
(string/slice "hello" -1 -2)  # => ""
cellularmitosisPlayground