MMTMMT Docs

Strings

Formatting, conversion, searching, and manipulation of strings.

All string functions are available under the str.* namespace.

Conversion and Formatting

str.toString

str.toString(value, format?) -> string

Converts a value to a string. When value is a number, an optional format controls output.

ParamTypeDefaultDescription
valueanyValue to convert
formatstringNumber format preset or pattern

Format presets:

PresetAliasDescription
"mintick""format.mintick"Rounds to the symbol's tick size
"percent""format.percent"Formats as percentage
"volume""format.volume"Compact volume notation (K, M, B)

You can also pass a custom pattern like "#.00" or "0,000.##".

str.toString(123.456, "mintick")  // "123.46" (depends on tick size)
str.toString(0.0534, "percent")   // "5.34%"
str.toString(1500000, "volume")   // "1.5M"
str.toString(3.14159, "#.00")     // "3.14"

str.format

str.format(template, ...args) -> string

Fills placeholders in a template string. Placeholders use {index} syntax with optional numeric formatting.

ParamTypeDescription
templatestringTemplate with {0}, {1} placeholders
...argsanyValues to insert
str.format("Price: {0}", 42000)
// "Price: 42000"

str.format("{0,number,#.00} / {1,number,#.0}", 3.14159, 99.5)
// "3.14 / 99.5"

Info

str.length

str.length(source) -> number

Returns the number of characters in a string.

str.length("hello")  // 5

str.includes

str.includes(source, sub) -> boolean

Returns true if source contains sub.

str.includes("hello world", "world")  // true
str.includes("hello world", "xyz")    // false

str.startsWith

str.startsWith(source, sub) -> boolean

Returns true if source starts with sub.

str.startsWith("binancef", "binance")  // true

str.endsWith

str.endsWith(source, sub) -> boolean

Returns true if source ends with sub.

str.endsWith("btc/usdt", "usdt")  // true

str.indexOf

str.indexOf(source, sub, occurrence?) -> number

Returns the index of the occurrence-th match of sub in source, or -1 if not found.

ParamTypeDefaultDescription
sourcestringString to search in
substringSubstring to find
occurrencenumber0Which occurrence (0 = first)
str.indexOf("a.b.c", ".")     // 1
str.indexOf("a.b.c", ".", 1)  // 3
str.indexOf("abc", "z")       // -1

Manipulation

str.split

str.split(source, separator) -> string[]

Splits a string into an array by separator.

str.split("a,b,c", ",")  // ["a", "b", "c"]

str.replace

str.replace(source, target, replacement, occurrence?) -> string

Replaces the occurrence-th match of target with replacement.

ParamTypeDefaultDescription
sourcestringInput string
targetstringSubstring to find
replacementstringReplacement text
occurrencenumber0Which occurrence to replace (0 = first)
str.replace("foo bar foo", "foo", "baz")     // "baz bar foo"
str.replace("foo bar foo", "foo", "baz", 1)  // "foo bar baz"

str.replaceAll

str.replaceAll(source, target, replacement) -> string

Replaces all occurrences of target.

str.replaceAll("foo bar foo", "foo", "baz")  // "baz bar baz"

str.substring

str.substring(source, begin, end?) -> string

Extracts a portion of the string from begin to end (exclusive). If end is omitted, extracts to the end.

ParamTypeDefaultDescription
sourcestringInput string
beginnumberStart index (inclusive)
endnumberend of stringEnd index (exclusive)
str.substring("hello", 1, 3)  // "el"
str.substring("hello", 2)     // "llo"

str.toUpperCase

str.toUpperCase(source) -> string

Converts to uppercase.

str.toUpperCase("hello")  // "HELLO"

str.toLowerCase

str.toLowerCase(source) -> string

Converts to lowercase.

str.toLowerCase("HELLO")  // "hello"

str.trim

str.trim(source) -> string

Removes leading and trailing whitespace.

str.trim("  hello  ")  // "hello"

str.repeat

str.repeat(source, count, separator?) -> string

Repeats a string count times with an optional separator between repetitions.

ParamTypeDefaultDescription
sourcestringString to repeat
countnumberNumber of repetitions
separatorstring""Separator between repetitions
str.repeat("ab", 3)        // "ababab"
str.repeat("ab", 3, "-")   // "ab-ab-ab"

On this page