String
val length : string -> nat
let length: (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.
let size_op (s : string) : nat = String.length s
Note that
String.size
is deprecated.
let size_op = (s: string): nat => String.length(s);
val sub : nat -> nat -> string -> string
let sub: (offset: nat, length: nat, s: string) => string
Extract a substring from a string based on the given offset and length. For example the string "abcd" given to the function below would return "bc".
let slice_op (s: string) : string = String.sub 1n 2n s
Note that
String.slice
is deprecated.
let slice_op = (s: string): string => String.sub(1n, 2n, s);
val concat : string -> string -> string
let concat: (a: string, b: string) => string
Concatenate two strings and return the result.
let concat_syntax (s : string) = String.concat s "test_literal"
Alternatively:
let concat_syntax_alt (s: string) = s ^ "test_literal"
let concat_syntax = (s: string): string => String.concat(s, "test_literal");
Alternatively:
let concat_syntax_alt = (s: string): string => s + "test_literal";
val concats : string list -> string
let concats: (ss: list<string>) => string
Concatenate together a list of string
and return the result.