These methods are called on string values and perform basic inspection or simple transformation.
Returns the number of characters in the string.
| Item | Description |
|---|---|
| Syntax | `string.length()` |
| Arguments | none |
| Returns | number |
Example:
'PlanetCNC'.length();
Returns the string value.
| Item | Description |
|---|---|
| Syntax | `string.to_string()` |
| Arguments | none |
| Returns | string |
Example:
'abc'.to_string(); // 'abc'
Checks whether the string contains a substring.
| Argument | Type | Description |
|---|---|---|
| `text` | any | Text to search for. |
Returns: boolean-style number.
Example:
'PlanetCNC'.contains('CNC'); // true
Checks whether the string starts with a prefix.
| Argument | Type | Description |
|---|---|---|
| `prefix` | any | Prefix text. |
Returns: boolean-style number.
Example:
'PlanetCNC'.startswith('Planet');
Checks whether the string ends with a suffix.
| Argument | Type | Description |
|---|---|---|
| `suffix` | any | Suffix text. |
Returns: boolean-style number.
Example:
'file.expr'.endswith('.expr');
Finds the first position of a substring.
| Argument | Type | Description |
|---|---|---|
| `text` | any | Text to search for. |
Returns: zero-based position, or `-1` when the text is not found.
Example:
'abcdef'.indexof('cd'); // 2 'abcdef'.indexof('xy'); // -1
Returns the string with characters in reverse order.
| Item | Description |
|---|---|
| Syntax | `string.reverse()` |
| Arguments | none |
| Returns | string |
Example:
'abc'.reverse(); // 'cba'
Previous: Number Methods
Next: String Slice Methods