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 first occurence of a substring.
lastIndexOf()Determines the index of the last occurrence of the specified value, searching backwards.
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.

Remarks

  • Note that 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
  • string the string to extract a substring from
  • startIndex the index of the first character to be included.
  • endIndex the index of the first character to be excluded. If omitted, all characters to the end of the string are included.

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, then 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
  • string the string to extract a substring from.

  • searchString the substring to check.

  • startIndex the index of the first character to be included. Defaults to the start of the string

  • 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
  • string the string to extract a substring from.

  • searchString the substring to check.

  • fromIndex the index of the last character to be included. Defaults to the end of the string.

  • 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
  • string the string.
  • Returns number of characters.

indexOf

Determines the index of first occurence of a substring.

indexOf(string: string, substring: string, startIndex?: integer): integer
  • searchString
  • fromIndex Searched backward from fromIndex. Defaults to end of string.
  • Returns: The index of the last occurrence of searchValue; -1 if not found.

lastIndexOf

Determines the index of the last occurrence of the specified value, searching backwards.

lastIndexOf(string: string, searchString: string, fromIndex?: integer): integer
  • searchString
  • fromIndex Searched backward from fromIndex. Defaults to end of string.
  • Returns: The index of the last occurrence of searchValue; -1 if not found.

toUpperCase

Convert all characters in a string to upper case.

toUpperCase(string: string): string
  • string the input string
  • Returns a new string with all uppercase character replaced with lower case.

Remarks:

  • 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
  • string the string to be converted.
  • Returns a new string with all uppercase character replaced with lower case.

Remarks:

  • 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
  • string the input string.
  • searchString The string to replace.
  • newSubstring The replacement string.

contains

Determines whether one string may be found within another string.

contains(string: string, searchString: string): boolean
  • string the input string.

  • searchString string to search for.

  • 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
  • string the input string.

  • index - the index of the character.

  • 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
  • string the input string.

  • targetLength the minimum length of the returned string.

  • padString - Applied (multiple times, if needed) from the start of the current string. Defaults to ' ' (Unicode Character U+0020 'SPACE').

  • 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
  • string the input string.

  • targetLength the minimum length of the returned string.

  • padString - Applied (multiple times, if needed) from the end of the current string. Defaults to ' ' (Unicode Character U+0020 'SPACE').

  • Returns a string that has at least targetLength characters.

trim

Removes whitespace from both ends of a string,

trim(string: string): string
  • string the input string

  • Returns a string without leading and trailing whitespace.

trimStart

Removes whitespace from the start of a string.

trimStart(string: string): string
  • string the input string

  • Returns a string with leading whitespace stripped.

trimEnd

Removes whitespace from the end of a string.

trimEnd(string: string): string
  • string the input string

  • Returns a string with trailing whitespace stripped.


Sign In