ligo/gitlab-pages/docs/reference/string.md
2020-02-07 05:27:23 -08:00

1.8 KiB

id title
string-reference String

String.size(s: string) : nat

Get the size of a string. Michelson only supports ASCII strings so for now you can assume that each character takes one byte of storage.

function string_size (const s: string) : nat is size(s)
let size_op (s: string) : nat = String.size s
let size_op = (s: string): nat => String.size(s);

String.length(s: string) : nat

Alias for String.size.

String.slice(pos1: nat, pos2: nat, s: string) : string

Get the substring of s between pos1 inclusive and pos2 inclusive. For example the string "tata" given to the function below would return "at".

function slice_op (const s : string) : string is
  begin skip end with string_slice(1n , 2n , s)
let slice_op (s: string) : string = String.slice 1n 2n s
let slice_op = (s: string): string => String.slice(1n, 2n, s);

String.sub(pos1: nat, pos2: nat, s: string) : string

Alias for String.slice.

String.concat(s1: string, s2: string) : string

Concatenate two strings and return the result.

function concat_op (const s : string) : string is
  begin skip end with string_concat(s , "toto")
let concat_syntax (s: string) = s ^ "test_literal"
let concat_syntax = (s: string) => s ++ "test_literal";