String Functions
Studio provides a set of functions for working with strings in expressions.
Function | Arguments Description |
---|---|
substring() | Extracts a specified substring from a given string. |
startsWith() | Determines whether a string begins with specific characters. |
endsWith() | Determines whether a string ends with specific characters. |
stringLength() | Determines the number of characters in the specified string. |
indexOf() | Determines the index of the first occurrence of a substring. |
lastIndexOf() | Determines the index of the last occurrence of the specified value, searching backward. |
toUpperCase() | Convert all characters in a string to upper case. |
toLowerCase() | Convert all characters in a string to lower case. |
replace() | Replaces substrings within a string. |
contains() | Determines whether one string may be found within another string. |
charAt() | Get a new string containing the single character unit located at the specified offset. |
padStart() | Pads the front of the input string with another string until the resulting string reaches the given length. |
padEnd() | Pads the end of the input string with another string until the resulting string reaches the given length. |
trim() | Removes whitespace from both ends of a string. |
trimStart() | Removes whitespace from the start of a string. |
trimEnd() | Removes whitespace from the end of a string. |
matches() | Returns true for strings that match the provided regex. |
firstMatch() | Returns the first string that matches given the provided regex. |
Remarks
- All indices into strings are zero-based, meaning that the first character has index
0
, not1
.
API Reference
substring
Extracts a specified substring from a given string.
substring(string: string, startIndex: integer, endIndex?: integer): string
Parameter | Type | Description |
---|---|---|
string | string | The string to extract a substring from. |
startIndex | int | The index of the first character to be included. |
endIndex | int | The index of the first character to be excluded. If omitted, all characters to the end of the string are included. |
Returns
Returns a new string containing the specified part of the given string.
Notes
- If startIndex is equal to
endIndex
,substring()
returns an empty string. - If
startIndex
is greater thanendIndex
, the effect ofsubstring()
is as if the two arguments were swapped.
startsWith
Determines whether a string begins with the characters of another string.
startsWith(string: string, searchString: string, startIndex: integer): boolean
Parameter | Type | Description |
---|---|---|
string | string | The string to extract a substring from. |
searchString | string | The substring to look for. |
startIndex | int | The index of the first character to be included. |
Returns
Returns true
or false
as appropriate.
Notes
This method is case-sensitive.
endsWith
Determines whether a string end with the characters of a specified string.
endsWith(string: string, searchString: string, fromIndex?: integer): boolean
Parameter | Type | Description |
---|---|---|
string | string | The string to extract a substring from. |
searchString | string | The substring to check for. |
fromIndex | int | The index of the last character to be included. Defaults to the end of the string. |
Returns
Returns true
or false
as appropriate.
Notes
This method is case-sensitive.
stringLength
Determines the number of characters in the specified string.
stringLength(string: string): integer
Parameter | Type | Description |
---|---|---|
string | string | The string to check for length. |
Returns
Returns the number of characters in the given string.
indexOf
Determines the index of first occurrence of a substring.
indexOf(string: string, substring: string, startIndex?: integer): integer
Parameter | Type | Description |
---|---|---|
string | string | The string to find a substring in. |
substring | string | The string to check for. |
fromIndex | int | The index to search backward from. Defaults to end of string. |
Returns
Returns the index of the first occurrence of substring
; -1 if not found.
lastIndexOf
Determines the index of the last occurrence of the specified value, searching backward.
lastIndexOf(string: string, searchString: string, fromIndex?: integer): integer
Parameter | Type | Description |
---|---|---|
string | string | The string to find a substring in. |
substring | string | The string to check for. |
fromIndex | int | The index to search backward from. Defaults to end of string. |
Returns
Returns the index of the last occurrence of substring
; -1 if not found.
toUpperCase
Convert all characters in a string to upper case.
toUpperCase(string: string): string
Parameter | Type | Description |
---|---|---|
string | string | The input string to convert to upper case. |
Returns
Returns a new string
with all lower cases characters replaced with upper case characters.
Notes
The specifics of case conversion may depend on the current locale, determined by the browser and the operating system.
toLowerCase
Convert all characters in a string to lower case.
toLowerCase(string: string): string
Parameter | Type | Description |
---|---|---|
string | string | The input string to convert to lower case. |
Returns
Returns a new string
with all upper case characters replaced with lower case characters.
Notes
The specifics of case conversion may depend on the current locale, determined by the browser and the operating system.
replace
Replaces substrings within a string.
replace(string: string, searchString: string, newSubstring: string): string
Parameter | Type | Description |
---|---|---|
string | string | The input string containing a substring to be replaced. |
searchString | string | The substring to be replaced. |
newSubstring | string | The replacement string. |
Returns
Returns a string with the replaced substring, or an unaltered string if no searchString
was found.
contains
Determines whether one string may be found within another string.
contains(string: string, searchString: string): boolean
Parameter | Type | Description |
---|---|---|
string | string | The input string to evaluate for a substring. |
searchString | string | The substring to search for. |
Returns
Returns true
if the searchString
is found inside the supplied string, otherwise false
.
charAt
Get a new string consisting of the single character unit located at a specified offset.
charAt(string: string, index: integer): string
Parameter | Type | Description |
---|---|---|
string | string | The input string. |
index | int | The index of the character. |
Returns
Returns a string containing the character at index
at the specified index. If index
is out of range, an empty string is returned.
padStart
Pads the front of the input string with another string until the resulting string reaches the given length.
padStart(string: string, targetLength: integer, padString?: string): string
Parameter | Type | Description |
---|---|---|
string | string | The input string. |
targetLength | int | The minimum length of the returned string. |
padString | string | Optional. Applied (multiple times, if needed) from the start of the current string. Defaults to ' ' (Unicode Character U+0020 'SPACE'). |
Returns
Returns a string that has at least targetLength
characters.
padEnd
Pads the end of the input string with another string until the resulting string reaches the given length.
padEnd(string: string, targetLength: integer, padString?: string): string
Parameter | Type | Description |
---|---|---|
string | string | The input string. |
targetLength | int | The minimum length of the returned string. |
padString | string | Optional. Applied (multiple times, if needed) from the end of the current string. Defaults to ' ' (Unicode Character U+0020 'SPACE'). |
Returns
Returns a string that has at least targetLength
characters.
trim
Removes whitespace from both ends of a string,
trim(string: string): string
Parameter | Type | Description |
---|---|---|
string | string | The input string. |
Returns
Returns a string without leading and trailing whitespace.
trimStart
Removes whitespace from the start of a string.
trimStart(string: string): string
Parameter | Type | Description |
---|---|---|
string | string | The input string. |
Returns
Returns a string with leading whitespace stripped.
trimEnd
Removes whitespace from the end of a string.
Parameter | Type | Description |
---|---|---|
string | string | The input string. |
Returns
Returns a string with trailing whitespace stripped.
matches
Determines whether a string matches the provided regex.
matches(string: string, regex: string): boolean
Parameter | Type | Description |
---|---|---|
string | string | The input string. |
regex | string | The regex argument to use in a search. |
Return
Returns true
if a string matches the provided regex, false
otherwise.
firstMatch
Finds the first string that matches the provided regex.
matches(string: string, regex: string): string
Parameter | Type | Description |
---|---|---|
string | string | The input string. |
regex | string | The regex argument to use in a search. |
Returns
Returns the first string that matches the provided regex.
Updated 12 months ago