Text

Functions to help build and modify text

Functions

index_of(searchString, searchValue, start) → {int}

The indexOf() method returns the position of the first occurrence of a specified value in a string. This method returns -1 if the value to search for never occurs.

Parameters:
Name Type Description
searchString string

Required. The string to search in

searchValue string

Required. The string to search for

start int

Optional. Default 0. At which position to start the search

Returns:
Type:
int

The position where the specified searchvalue occurs for the first time, or -1 if it never occurs

Examples
// returns 3
index_of('abcdefg', 'cde')
// returns -1
index_of('abcdefg', 'cde', 4)

length(string) → {int}

Returns the length of a string (number of characters).

Parameters:
Name Type Description
string string

Required. The string

Returns:
Type:
int

The length of a string

Example
// returns 3
length('ABC')

lower(string) → {string}

The lower() function converts a string to lowercase letters.

Parameters:
Name Type Description
string string

Required. The string

Returns:
Type:
string

The value of a string converted to lowercase

Example
// returns 'abc'
lower('ABC')

replace(searchString, searchValue, replaceString) → {string}

The replace() function searches a string for a specified value and returns a new string where the first specified value is replaced.

Parameters:
Name Type Description
searchString string

Required. The string to search in

searchValue string

Required. The value that will be replaced by the new value

replaceString string

Required. The value to replace the search value with

Returns:
Type:
string

A new String, where the first specified value have been replaced by the new value

Example
// returns 'konect is Great!'
replace('konect is OK', 'OK', 'Great!')

replace_all(searchString, searchValue, replaceString) → {string}

The replace_all() function searches a string for a specified value and returns a new string where all occurrences of the specified value are replaced.

Parameters:
Name Type Description
searchString string

Required. The string to search in

searchValue string

Required. The value that will be replaced by the new value

replaceString string

Required. The value to replace the search value with

Returns:
Type:
string

A new String, where all occurrences of the specified value have been replaced by the new value

Example
// returns 'A,B,C'
replace('A B C', ' ', ',')

substring(string, start, end) → {string}

The substring() function extracts the characters from a string, between two specified indices, and returns the new sub string. This method extracts the characters in a string between "start" and "end", not including "end" itself.

Parameters:
Name Type Description
string string

Required. The string to substring

start int

Required. The position where to start the extraction. First character is at index 0

end int

Optional. The position (up to, but not including) where to end the extraction. If omitted, it extracts the rest of the string

Returns:
Type:
string

A new String containing the extracted characters

Examples
// returns 'konect'
substring('hello konect', 6);
// returns 'kon'
substring('hello konect', 6, 9);

trim(string) → {string}

The trim() function removes whitespace from both sides of a string.

Parameters:
Name Type Description
string string

Required. The string

Returns:
Type:
string

A String, representing the string with removed whitespace from both ends

Example
// returns 'Some text'
trim('  Some text  ')

upper(string) → {string}

The upper() method converts a string to uppercase letters.

Parameters:
Name Type Description
string string

Required. The string

Returns:
Type:
string

The value of a string converted to uppercase

Example
// returns 'ABC'
upper('abc')