strings
strings.tolk Tolk standard library file
Definitions
string.depth
@pure
fun string.depth(self): intReturns snake depth of a string. Example: "abcd" has depth 0, it's a flat string. Example: "ab" + (ref "cd") has depth 1. Example: "a" + (ref "bc" + (ref "d" + (ref ""))) has depth 3.
Source codestring.calculateLength
@pure
@inline_ref
fun string.calculateLength(self): intCalculates length of a string in bytes (not unicode symbols, just bytes). Since strings are stored in snake format (chain of cells), this requires traversing all cells.
Source codestring.hash
@pure
@inline_ref
fun string.hash(self): uint256Computes a content hash of a string, traversing all snake cells. The hash is the same regardless of snake layout: "abcd", "ab" + (ref "cd"), "a" + (ref "bcd" + (ref "")) all produce the same hash. Uses FNV-1a hashing with standard 128-bit parameters.
Source codestring.equalTo
@pure
fun string.equalTo(self, another: string): boolCompares two strings, considering snake cells. For example, "abcd" is equal to "ab" + (ref "cd") is equal to "a" + (ref "bc" + (ref "d")).
Source codeint.toDecimalString
fun int.toDecimalString(self): stringConverts an integer to its decimal string representation. Returns a string (a TVM cell on a stack).
Source codeStringBuilder
struct StringBuilder {
private chunks: array<string> = []
}A utility for building strings at runtime by appending multiple parts. The result is a valid snake-format string.
var s = StringBuilder.create().append("Hello, ").append(userName).append("!").build();After this, s will be a chain of cells: "Hello, " + (ref userName + (ref "!"))
StringBuilder.create
fun StringBuilder.create(): StringBuilderCreates an empty StringBuilder.
var s = StringBuilder.create().append(...).build();StringBuilder.append
fun StringBuilder.append(mutate self, s: string): selfAppends a string to the builder. The string may itself be a snake chain.
Source codeStringBuilder.appendInt
@inline_ref
fun StringBuilder.appendInt(mutate self, n: int): selfAppends an integer as its decimal representation.
For example, sb.appendInt(-42) appends "-42".
StringBuilder.build
@inline_ref
fun StringBuilder.build(self): stringBuilds the final string by concatenating all appended parts into a snake chain.
The result is a valid snake-format string where each cell contains data and optionally a ref to next.
Throws an exception if append() was not called (a builder is empty).
string_prefixed0x
type string_prefixed0x = stringA string, which contents starts with 0x00/0x01 byte. By standard, offchain explorers/APIs may treat contents of a string based on 0xXX prefixes:
- 0x00 + "str" — means "this is a regular snake-encoded string"
- 0x01 + "str" — means "this is an off-chain content URL" Used in jettons and NFTs for responses from GET methods to comply with TEPs (token standards).
string.prefixWith00
fun string.prefixWith00(self): string_prefixed0xGiven "str", prefix it with 0x00 byte. Logically it makes a string "\x00str"; physically, it's 0x00 + ref "str". See string_prefixed0x.
Source codestring.prefixWith01
fun string.prefixWith01(self): string_prefixed0xGiven "str", prefix it with 0x01 byte. Logically it makes a string "\x01str"; physically, it's 0x01 + ref "str". See string_prefixed0x.
Source codeLast updated on