Functions -
stringutils
contains |
Checks whether the given string contains a particular substring. |
equalsIgnoreCase |
Checks if two strings are equal ignoring the case of the strings. |
hashCode |
Returns a hash code for a given string. |
lastIndexOf |
Returns the last index of the provided substring within a string. |
matches |
Checks whether the given string matches the provided regex. |
replace |
Replaces each occurrence of the provided |
replaceAll |
Replaces each occurrence of the substrings, which matches the provided regular expression from the given original string value with the provided replacement string. |
replaceFirst |
Replaces the first substring that matches the given regular expression with
the provided |
split |
Returns an array of strings by splitting a string using the provided delimiter. |
toBoolean |
Returns a boolean value of a given string. |
Checks whether the given string contains a particular substring.
boolean contains = stringutils:contains("Ballerina", "in");
Parameters
- originalString string
-
The string to check whether it contains the
substring
- substring string
-
The substring to find within the
originalString
-
Return Type
(boolean) true
if theoriginalString
contains the providedsubstring
or elsefalse
Checks if two strings are equal ignoring the case of the strings.
boolean isEqual = stringutils:equalsIgnoreCase("BaLLerinA", "ballERina");
Parameters
- firstString string
-
The first string to compare
- secondString string
-
The second string to compare
-
Return Type
(boolean) true
if the two strings are equal or elsefalse
Returns a hash code for a given string.
int hashCode = stringutils:hashCode("Ballerina");
Parameters
- stringValue string
-
The string to generate the hash code
-
Return Type
(int) The hash code for the given string
Returns the last index of the provided substring within a string.
int lastIndex = stringutils:lastIndexOf("int values in Ballerina", "in");
Parameters
- originalString string
-
The string to search for the index of the
substring
- substring string
-
The string to search in the
originalString
-
Return Type
(int) Starting index of the last appearance of the provided substring if the
originalString
contains thesubstring
or else-1
Checks whether the given string matches the provided regex.
boolean isMatched = stringutils:matches("Ballerina is great", "Ba[a-z ]+");
Parameters
- stringToMatch string
-
The string to match the regex
- regex string
-
The regex to match the string
-
Return Type
(boolean) true
if the provided string matches the regex or elsefalse
Replaces each occurrence of the provided substring
inside the provided
originalString
with the specified replacement
string.
string result = stringutils:replace("Ballerina is great", " ", "_");
Parameters
- originalString string
-
The original string to replace the substrings
- stringToReplace string
-
The string to replace within the
originalString
- replacement string
-
The
replacement
string to replace the occurrences of thestringToReplace
-
Return Type
(string) The string with the replaced substrings
Replaces each occurrence of the substrings, which matches the provided regular expression from the given original string value with the provided replacement string.
string result = stringutils:replaceAll("Ballerina is great", "\s+", "_");
Parameters
- originalString string
-
The original string to replace the occurrences of the substrings that match the provided
regex
- regex string
-
The regex to match the substrings in the
originalString
to be replaced
- replacement string
-
The
replacement
string to replace the subsgrings, which match theregex
-
Return Type
(string) The resultant string with the replaced substrings
Replaces the first substring that matches the given regular expression with
the provided replacement
string.
string result = stringutils:replaceFirst("Ballerina is great", "\s+", "_");
Parameters
- originalString string
-
The original string to replace the occurrences of the substrings that match the provided
regex
- regex string
-
The regex to match the first substring in the
originalString
to be replaced
- replacement string
-
The
replacement
string to replace the first substring, which matches theregex
-
Return Type
(string) The resultant string with the replaced substring
Returns an array of strings by splitting a string using the provided delimiter.
string[] result = stringutils:split("Ballerina is great", " ");
Parameters
- receiver string
-
The string to split
- delimiter string
-
The delimiter to split by
-
Return Type
(string[]) An array of strings containing the individual strings that are split
Returns a boolean value of a given string.
boolean result = stringutils:toBoolean("true");
Parameters
- stringValue string
-
string value to convert to a boolean
-
Return Type
(boolean) true
if the string is"true"
(without considering the case) or elsefalse