Ballerina API Documentation

Functions of ballerina.lang.strings package

function contains(string mainString, string subString) (boolean )

Returns a Boolean value indicating whether a string contains the specified substring

Parameters:

Parameter NameData TypeDescription
mainStringstringThe original string argument
subStringstringThe substring to be compared

Return Parameters:

Return VariableData TypeDescription
booleanTrue if the string contains the substring; false otherwise

function equalsIgnoreCase(string mainString, string anotherString) (boolean )

Compares two strings, ignoring the case of the strings

Parameters:

Parameter NameData TypeDescription
mainStringstringThe original string argument
anotherStringstringThe string to be compared

Return Parameters:

Return VariableData TypeDescription
booleanTrue if the strings are equal; false otherwise

function hasPrefix(string mainString, string prefix) (boolean )

Returns a Boolean value indicating whether a string starts with the specified prefix

Parameters:

Parameter NameData TypeDescription
mainStringstringThe original string argument
prefixstringThe prefix to be compared

Return Parameters:

Return VariableData TypeDescription
booleanTrue if the string starts with the prefix; false otherwise

function hasSuffix(string mainString, string suffix) (boolean )

Returns a Boolean value indicating whether the string ends with specified suffix

Parameters:

Parameter NameData TypeDescription
mainStringstringThe original string argument
suffixstringThe suffix to be compared

Return Parameters:

Return VariableData TypeDescription
booleanTrue if the string ends with the suffix; false otherwise

function indexOf(string mainString, string subString) (int )

Returns the first index of the first occurence of the substring within the specified string

Parameters:

Parameter NameData TypeDescription
mainStringstringThe original string argument
subStringstringThe substring to search for

Return Parameters:

Return VariableData TypeDescription
intThe index of the first occurence of the substring

function lastIndexOf(string mainString, string subString) (int )

Returns the first index of the last occurence of the substring within the specified string

Parameters:

Parameter NameData TypeDescription
mainStringstringThe original string argument
subStringstringThe substring to search for

Return Parameters:

Return VariableData TypeDescription
intThe index of the last occurence of the substring

function length(string s) (int )

Returns the length of the specified string

Parameters:

Parameter NameData TypeDescription
sstringThe original string argument

Return Parameters:

Return VariableData TypeDescription
intThe length of the specified string

function replace(string mainString, string replacePattern, string replaceWith) (string )

Replaces all instances of the replacePattern string with the replaceWith string and returns the result

Parameters:

Parameter NameData TypeDescription
mainStringstringThe original string argument
replacePatternstringThe pattern to search for
replaceWithstringThe replacement string

Return Parameters:

Return VariableData TypeDescription
stringThe derived string

function replaceAll(string mainString, string replacePattern, string replaceWith) (string )

Replaces each substring of the mainString that matches the given regular expression with the given replacement

Parameters:

Parameter NameData TypeDescription
mainStringstringThe original string argument
replacePatternstringThe regular expression to search for
replaceWithstringThe replacement string

Return Parameters:

Return VariableData TypeDescription
stringThe derived string

function replaceFirst(string mainString, string replacePattern, string replaceWith) (string )

Replaces the first instance of the replacePattern with the replaceWith string and returns the result

Parameters:

Parameter NameData TypeDescription
mainStringstringThe original string argument
replacePatternstringThe pattern to search for
replaceWithstringThe replacement string

Return Parameters:

Return VariableData TypeDescription
stringThe derived string

function split(string mainString, string regex) (string[] )

Splits the string with the given regular expression to produce a string array.

Parameters:

Parameter NameData TypeDescription
mainStringstringThe original string argument
regexstringThe regex to split the string

Return Parameters:

Return VariableData TypeDescription
string[]string[]: The split string array

function subString(string mainString, int from, int to) (string )

Returns a new string that is the substring of the specified string

Parameters:

Parameter NameData TypeDescription
mainStringstringThe original string argument
fromintThe starting index
tointThe ending index

Return Parameters:

Return VariableData TypeDescription
stringThe derived sub string

function toBlob(string s, string encoding) (blob )

Converts string to a BLOB

Parameters:

Parameter NameData TypeDescription
sstringb: string value to be converted
encodingstringEncoding to used in the conversion

Return Parameters:

Return VariableData TypeDescription
blobstring: BLOB representation of the given String

function toLowerCase(string s) (string )

Returns a string with all the characters converted to lowercase

Parameters:

Parameter NameData TypeDescription
sstringThe original string argument

Return Parameters:

Return VariableData TypeDescription
stringThe string converted to lowercase

function toUpperCase(string s) (string )

Returns a string with all the characters converted to uppercase

Parameters:

Parameter NameData TypeDescription
sstringThe original string argument

Return Parameters:

Return VariableData TypeDescription
stringThe string converted to uppercase

function trim(string s) (string )

Returns a trimmed string by omitting the leading and trailing whitespaces of the original string

Parameters:

Parameter NameData TypeDescription
sstringThe original string argument

Return Parameters:

Return VariableData TypeDescription
stringThe derived string

function unescape(string s) (string )

Returns an unescaped string by omitting the escape characters of the original string

Parameters:

Parameter NameData TypeDescription
sstringThe original string argument

Return Parameters:

Return VariableData TypeDescription
stringThe derived string

function valueOf(any value) (string )

Returns a string representation of an integer argument

Parameters:

Parameter NameData TypeDescription
valueanyAn integer argument

Return Parameters:

Return VariableData TypeDescription
stringString representation of the specified integer argument


Menu

  • Functions
    • contains(string mainString, string subString) (boolean )
    • equalsIgnoreCase(string mainString, string anotherString) (boolean )
    • hasPrefix(string mainString, string prefix) (boolean )
    • hasSuffix(string mainString, string suffix) (boolean )
    • indexOf(string mainString, string subString) (int )
    • lastIndexOf(string mainString, string subString) (int )
    • length(string s) (int )
    • replace(string mainString, string replacePattern, string replaceWith) (string )
    • replaceAll(string mainString, string replacePattern, string replaceWith) (string )
    • replaceFirst(string mainString, string replacePattern, string replaceWith) (string )
    • split(string mainString, string regex) (string[] )
    • subString(string mainString, int from, int to) (string )
    • toBlob(string s, string encoding) (blob )
    • toLowerCase(string s) (string )
    • toUpperCase(string s) (string )
    • trim(string s) (string )
    • unescape(string s) (string )
    • valueOf(any value) (string )

Copyright 2017 Ballerina API Documentation