string.length
string.lenght -> number
Get the length of a string
Returns
number
string length (bytes)
Example
let a = "Hello World";
print( a.length ); // 11
Byte-level methods carried by every string: slice, at, indexOf — plus the chr() global for building strings from byte values.
Every mJS string carries these built-in methods. Remember that mJS strings are byte strings (see The mJS Language): indices count bytes, not Unicode characters, and strings may hold arbitrary binary data.
string.lenght -> number
Get the length of a string
number
string length (bytes)
let a = "Hello World";
print( a.length ); // 11
string.number() -> number
Converts a string to a numeric value — the inverse of `number.toFixed()` and `string()`. (Global function.)
Converts a text string into a number type variable
Wrapper to the strtod c function.
number
Number value of string
let text = "123.456";
let number = text.number();
print( number ); // 123.456
'some_string'.slice(start, end) → string
Returns a substring between two indices.
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| start | number | yes | — | Start index (inclusive). |
| end | number | yes | — | End index (exclusive). |
string
The substring.
'abcdef'.slice(1,3) === 'bc';
'abc'.at(index) → number
Returns the numeric byte value at a string index.
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| index | number | yes | — | Byte index into the string. |
number
The byte value at that index.
'abc'.at(0) === 0x61;
'abc'.indexOf(substr, [fromIndex]) → number
Returns the index of the first occurrence of a substring, or −1 if not found.
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| substr | string | yes | — | Substring to search for. |
| fromIndex | number | optional | 0 | Index to start searching from. |
number
Index of the first occurrence, or −1 if not found.
'abc'.indexOf('bc') === 1;
chr(n) → string | null
Returns a 1-byte string whose byte value is n — the inverse of string.at(). (Global function.)
Builds a single-byte string from a numeric value. If n is not numeric or is
outside the 0–255 range, null is returned.
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| n | number | yes | — | Byte value, 0–255. |
string | null
A 1-byte string, or null for invalid input.
chr(0x61) === 'a';