Table of Contents



String Basic Methods

These methods are called on string values and perform basic inspection or simple transformation.


length()

Returns the number of characters in the string.

Item Description
Syntax `string.length()`
Arguments none
Returns number

Example:

'PlanetCNC'.length();

to_string()

Returns the string value.

Item Description
Syntax `string.to_string()`
Arguments none
Returns string

Example:

'abc'.to_string();    // 'abc'

contains(text)

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

startswith(prefix)

Checks whether the string starts with a prefix.

Argument Type Description
`prefix` any Prefix text.

Returns: boolean-style number.

Example:

'PlanetCNC'.startswith('Planet');

endswith(suffix)

Checks whether the string ends with a suffix.

Argument Type Description
`suffix` any Suffix text.

Returns: boolean-style number.

Example:

'file.expr'.endswith('.expr');

indexof(text)

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

reverse()

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