String Functions

Studio provides a set of functions for working with strings in expressions.

FunctionArguments 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, not 1.

API Reference

substring

Extracts a specified substring from a given string.

substring(string: string, startIndex: integer, endIndex?: integer): string
ParameterTypeDescription
stringstringThe string to extract a substring from.
startIndexintThe index of the first character to be included.
endIndexintThe 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 than endIndex, the effect of substring() 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
ParameterTypeDescription
stringstringThe string to extract a substring from.
searchStringstringThe substring to look for.
startIndexintThe 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
ParameterTypeDescription
stringstringThe string to extract a substring from.
searchStringstringThe substring to check for.
fromIndexintThe 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
ParameterTypeDescription
stringstringThe 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
ParameterTypeDescription
stringstringThe string to find a substring in.
substringstringThe string to check for.
fromIndexintThe 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
ParameterTypeDescription
stringstringThe string to find a substring in.
substringstringThe string to check for.
fromIndexintThe 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
ParameterTypeDescription
stringstringThe 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
ParameterTypeDescription
stringstringThe 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
ParameterTypeDescription
stringstringThe input string containing a substring to be replaced.
searchStringstringThe substring to be replaced.
newSubstringstringThe 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
ParameterTypeDescription
stringstringThe input string to evaluate for a substring.
searchStringstringThe 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
ParameterTypeDescription
stringstringThe input string.
indexintThe 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
ParameterTypeDescription
stringstringThe input string.
targetLengthintThe minimum length of the returned string.
padStringstringOptional. 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
ParameterTypeDescription
stringstringThe input string.
targetLengthintThe minimum length of the returned string.
padStringstringOptional. 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
ParameterTypeDescription
stringstringThe input string.

Returns

Returns a string without leading and trailing whitespace.

trimStart

Removes whitespace from the start of a string.

trimStart(string: string): string
ParameterTypeDescription
stringstringThe input string.

Returns

Returns a string with leading whitespace stripped.

trimEnd

Removes whitespace from the end of a string.

ParameterTypeDescription
stringstringThe 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
ParameterTypeDescription
stringstringThe input string.
regexstringThe 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
ParameterTypeDescription
stringstringThe input string.
regexstringThe regex argument to use in a search.

Returns

Returns the first string that matches the provided regex.