2.9 KiB
2.9 KiB
id | title | description | hide_table_of_contents |
---|---|---|---|
string-reference | String | Operations for strings. | true |
import Syntax from '@theme/Syntax'; import SyntaxTitle from '@theme/SyntaxTitle';
function length : string -> nat val length : string -> nat let length: string => natGet 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 String.length(s)
Note that
size
andString.size
are deprecated.
let size_op (s: string) : nat = String.length s
Note that
String.size
is deprecated.
let size_op = (s: string): nat => String.length(s);
function sub : nat -> nat -> string -> string val sub : nat -> nat -> string -> string let sub: (nat, nat, string) => stringNote that
String.size
is deprecated.
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".
function slice_op (const s : string) : string is String.sub(1n , 2n , s)
Note that
string_slice
is deprecated.
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);
function concat : string -> string -> string val concat : string -> string -> string let concat: (string, string) => stringNote that
String.slice
is deprecated.
Concatenate two strings and return the result.
function concat_op (const s : string) : string is String.concat(s, "toto")
Alternatively:
function concat_op_alt (const s : string) : string is s ^ "toto"
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.concat(s, "test_literal");
Alternatively:
let concat_syntax_alt = (s: string) => s ++ "test_literal";