Skip to main content

String functions

equals#

The equals() function takes a string as arguments. It compares it with the reference string, and returns True if both are found to be equal. Otherwise, it returns False.

Note: This function performs a case-sensitive search.

Syntax:

stringVariable.equals(String anotherString)

Parameters:

ParamData typeDescription
anotherStringStringThe string to be compared.

Returns: Boolean

Example:

stringVariable = "Work Order";
log stringVariable.equals("Work Order"); // truelog stringVariable.equals("Alarms"); // false

contains#

The contains() function takes searchString as argument. It returns True if reference stringVariable contains the searchString. Otherwise, it returns False .

Note: This function performs a case-sensitive search.

Syntax:

stringVariable.contains(String searchString)

Parameters:

ParamData typeDescription
searchStringStringThe string to be searched for, in the main string.

Returns: Boolean

Example:

stringVariable = "Work Order";
log stringVariable.contains("Order"); // truelog stringVariable.contains("Alarms"); // false

charAt#

The charAt() is a function that returns the character from the specified index. Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character in a string.

Syntax:

stringVariable.charAt(Number index)

Parameters:

ParamData typeDescription
indexNumberThe index of the character which will be returned.

Returns: String

Example:

stringVariable = "Work Order";
log stringVariable.charAt(3); // k

length#

The length() function returns the count of characters (including spaces) in the given reference string.

Syntax:

stringVariable.length()

Returns: Number

Example:

stringVariable = "Work Order";
log stringVariable.length(); // 10

subString#

The subString function takes start_index, and end_index as arguments. It returns a piece of text containing characters between the specified indices (including the start_index and excluding the end_index).

Note:

  • Index starts from 0
  • The start_index and/or end_index should not exceed the length of the source_text. If it exceeds, an error will be encountered during execution.
  • The end_index must be greater than or equal to the start_index, failing which an error will be encountered during runtime.
  • If start_index and end_index are the same, then the function will return an empty text.

Syntax:

stringVariable.subString(Number startIndex, Number endIndex)

Parameters:

ParamData typeDescription
startIndexNumberThe index starting from which the characters in the source text will be returned.
endIndexNumberOptional The index until which the characters in the source text will be returned. If omitted, the rest of the text (from the start index) will be returned.

Returns: String

Example:

stringVariable = "Work Order Management";
log stringVariable.subString(5, 10); // Order

indexOf#

The indexOf() function takes searchString as arguments. It returns the first occurrence index of searchString's first character in the reference string.

If the searchString is not found in the string, it returns -1.

Syntax:

stringVariable.indexOf(String searchString)

Parameters:

ParamData typeDescription
searchStringStringThe string from which the index number will be returned.

Returns: Number

Example:

stringVariable = "Work Order Management";
log stringVariable.indexOf("Order"); // 5

trim#

The trim() function returns the string after removing all leading and trailing spaces from reference string.

Syntax:

stringVariable.trim()

Returns: String

Example:

stringVariable = "   Work Order Management   ";
log stringVariable.trim(); // "Work Order Management"

lastIndexOf#

The lastIndexOf() function takes searchString as argument. It returns the last occurrence index of searchString's first character in the reference string.

If the searchString is not found in the reference string, it returns -1.

Syntax:

stringVariable.lastIndexOf(String searchString)

Parameters:

ParamData typeDescription
searchStringStringThe string from which the index number will be returned.

Returns: Number

Example:

stringVariable = "Work Order Management & Inventory Order Management";
log stringVariable.lastIndexOf("Order"); // 34

split#

The split() function splits a string into an list of substrings, and returns the new list. If an empty string ("") is used as the separator, the string is split between each character. The split() method does not change the original string.

Syntax:

stringVariable.split(String separator)

Parameters:

ParamData typeDescription
separatorStringSpecifies the character or the regular expression to use for splitting the string.

Returns: List

Example:

stringVariable = "Work Order Management & Inventory Order Management";
log stringVariable.split("&"); // [Work Order Management ,  Inventory Order Management]

toUpperCase#

The toUpperCase() function returns all characters with upper case as output.

Syntax:

stringVariable.toUpperCase()

Parameters:

ParamData typeDescription
stringVariableStringThe string for which the each characters to be changed to uppercase.

Returns: String

Example:

stringVariable = "Work Order Management";log stringVariable.toUpperCase(); //WORK ORDER MANAGEMENT

toLowerCase#

The toLowerCase() function returns all characters with lower case as output.

Syntax:

stringVariable.toLowerCase()

Parameters:

ParamData typeDescription
stringVariableStringThe string for which the each characters to be changed to lowercase.

Returns: String

Example:

stringVariable = "Work Order Management";log stringVariable.toLowerCase(); //work order management

replace#

The replace() function takes set of character(string) or a character from the string and another set of character(string) or a character as arguments. It replaces the old character with the new character and returns string as output.

Syntax:

stringVariable.replace(String oldCharacter,String newCharacter)

Parameters:

ParamData typeDescription
stringVariableStringThe string which should be replaced.
old characterStringThe character or string which need to be changed in the given string.
new characterStringThe character or string which should replace the old character.

Returns: String

Example:

stringVariable = "book";log stringVariable.replace("o","p");  //bppk
stringVariable = "Welcome to Facilio.com";log stringVariable.replace("Facilio","FacilioTutorial"); //Welcome to FacilioTutorial.com

replaceAll#

The replaceAll() function takes string to be found on the reference string and a string to be replaced as arguments. It replaces the string or regex matching string with the given string and returns string as output.

Syntax:

stringVariable.replaceAll(String oldCharacter,String newCharacter)

Parameters:

ParamData typeDescription
stringVariableStringThe whole string.
old stringStringThe string which to be replaced.
new stringStringThe string which should replace the matching regex string.

Returns: String

Example:

stringVariable = "Welcome to Facilio.com";log stringVariable.replaceAll("Facilio","FacilioTutorial"); //FacilioTutorial

addDoubleQuotes#

The addDoubleQuotes() function adds ' " '(double quotes) to the end of string and returns it.

Syntax:

stringVariable.addDoubleQuotes()

Parameters:

ParamData typeDescription
stringVariableStringThe whole string to which the double quotes to be added at last.

Returns: String

Example:

stringVariable = "Facilio";log stringVariable.addDoubleQuotes(); // Facilio"

encloseDoubleQuotes#

The encloseDoubleQuotes() function adds ' " '(double quotes) to the start and end of string and returns it.

Syntax:

stringVariable.encloseDoubleQuotes()

Parameters:

ParamData typeDescription
stringVariableStringThe whole string to which the double quotes to be added at start and end.

Returns: String

Example:

stringVariable = "Facilio";log stringVariable.encloseDoubleQuotes(); // "Facilio"

match#

The match function takes a string or a regular expression as arguments. It compares it with the reference string, and returns an array with the matches. Otherwise, it returns null if no match is found.

Note: This function performs a case-sensitive search.

Syntax:

stringVariable.match(String anotherString)

Parameters:

ParamData typeDescription
anotherStringStringThe string to be compared.

Returns: List

Example:

text = "The inspection module dealing with handlings of inspection forms";subString="ing";result = text.match(subString);log result; //[ing, ing]