String functions
#
equalsThe 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:
Param | Data type | Description |
---|---|---|
anotherString | String | The string to be compared. |
Returns: Boolean
Example:
stringVariable = "Work Order";
log stringVariable.equals("Work Order"); // truelog stringVariable.equals("Alarms"); // false
#
containsThe 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:
Param | Data type | Description |
---|---|---|
searchString | String | The string to be searched for, in the main string. |
Returns: Boolean
Example:
stringVariable = "Work Order";
log stringVariable.contains("Order"); // truelog stringVariable.contains("Alarms"); // false
#
charAtThe 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:
Param | Data type | Description |
---|---|---|
index | Number | The index of the character which will be returned. |
Returns: String
Example:
stringVariable = "Work Order";
log stringVariable.charAt(3); // k
#
lengthThe 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
#
subStringThe 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:
Param | Data type | Description |
---|---|---|
startIndex | Number | The index starting from which the characters in the source text will be returned. |
endIndex | Number | Optional 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
#
indexOfThe 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:
Param | Data type | Description |
---|---|---|
searchString | String | The string from which the index number will be returned. |
Returns: Number
Example:
stringVariable = "Work Order Management";
log stringVariable.indexOf("Order"); // 5
#
trimThe 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"
#
lastIndexOfThe 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:
Param | Data type | Description |
---|---|---|
searchString | String | The string from which the index number will be returned. |
Returns: Number
Example:
stringVariable = "Work Order Management & Inventory Order Management";
log stringVariable.lastIndexOf("Order"); // 34
#
splitThe 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:
Param | Data type | Description |
---|---|---|
separator | String | Specifies 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]
#
toUpperCaseThe toUpperCase() function returns all characters with upper case as output.
Syntax:
stringVariable
.toUpperCase()
Parameters:
Param | Data type | Description |
---|---|---|
stringVariable | String | The string for which the each characters to be changed to uppercase. |
Returns: String
Example:
stringVariable = "Work Order Management";log stringVariable.toUpperCase(); //WORK ORDER MANAGEMENT
#
toLowerCaseThe toLowerCase() function returns all characters with lower case as output.
Syntax:
stringVariable
.toLowerCase()
Parameters:
Param | Data type | Description |
---|---|---|
stringVariable | String | The string for which the each characters to be changed to lowercase. |
Returns: String
Example:
stringVariable = "Work Order Management";log stringVariable.toLowerCase(); //work order management
#
replaceThe 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:
Param | Data type | Description |
---|---|---|
stringVariable | String | The string which should be replaced. |
old character | String | The character or string which need to be changed in the given string. |
new character | String | The 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
#
replaceAllThe 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:
Param | Data type | Description |
---|---|---|
stringVariable | String | The whole string. |
old string | String | The string which to be replaced. |
new string | String | The string which should replace the matching regex string. |
Returns: String
Example:
stringVariable = "Welcome to Facilio.com";log stringVariable.replaceAll("Facilio","FacilioTutorial"); //FacilioTutorial
#
addDoubleQuotesThe addDoubleQuotes() function adds ' " '(double quotes) to the end of string and returns it.
Syntax:
stringVariable
.addDoubleQuotes()
Parameters:
Param | Data type | Description |
---|---|---|
stringVariable | String | The whole string to which the double quotes to be added at last. |
Returns: String
Example:
stringVariable = "Facilio";log stringVariable.addDoubleQuotes(); // Facilio"
#
encloseDoubleQuotesThe encloseDoubleQuotes() function adds ' " '(double quotes) to the start and end of string and returns it.
Syntax:
stringVariable
.encloseDoubleQuotes()
Parameters:
Param | Data type | Description |
---|---|---|
stringVariable | String | The whole string to which the double quotes to be added at start and end. |
Returns: String
Example:
stringVariable = "Facilio";log stringVariable.encloseDoubleQuotes(); // "Facilio"
#
matchThe 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:
Param | Data type | Description |
---|---|---|
anotherString | String | The 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]