pdk.util.String
functions to operate with strings
Functions
capitalize
Capitalizes a String changing the first character to title case. No other characters are changed. Example: String.capitalize('teST') will return 'TeST'.
Arguments:
input :: pdk.core.String - the String to capitalize.
Result:
output :: pdk.core.String - the capitalized String.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
concat
Concatenates the second defined string to the end of the first defined string.
Arguments:
input :: pdk.core.String - the source string.
toConcat :: pdk.core.String - concatenated to the end of the result String.
Result:
output :: pdk.core.String - represents the concatenation of the first argument string followed by the second string argument's characters.
Possible exceptions
NullPointerException - throws if the input or toConcat argument is
NULL
contains
Returns true if and only if the first defined string contains the second defined string.
Arguments:
input :: pdk.core.String - the source string.
toFind :: pdk.core.String - the text to search for.
Result:
output :: pdk.core.Boolean - true if the first argument String contains the second argument String, false otherwise.
Possible exceptions
NullPointerException - throws if the input or toFind argument is
NULL
countMatches
Counts how many times the substring appears in the larger string.
Arguments:
input :: pdk.core.String - the String to check, may be null.
toMatch :: pdk.core.String - the substring to count, may be null.
Result:
output :: pdk.core.Integer - the number of occurrences, 0 if either String is null.
difference
Compares two Strings, and returns the portion where they differ. More precisely, return the remainder of the second String, starting from where it's different from the first. This means that the difference between 'abc' and 'ab' is the empty String and not 'c'.
Examples:
String.difference('abcde', 'abcfgh xyz')='fgh xyz'
String.difference('test', 'test some')=' some'
Arguments:
input :: pdk.core.String - the first String, may be null.
toCompare :: pdk.core.String - the second String, may be null.
Result:
output :: pdk.core.String - the portion of the second String where it differs from the first one; returns the empty String if they are equal.
endsWith
Tests if this string ends with the specified suffix.
Arguments:
input :: pdk.core.String - the source string.
toCheck :: pdk.core.String - the end suffix.
Result:
output :: pdk.core.Boolean - true if the character sequence represented by the second argument is a suffix of the character sequence represented by the first argument; false otherwise. Note that the result will be true if the second argument is the empty string or is equal to the first argument.
Possible exceptions
NullPointerException - throws if the input or toCheck argument is
NULL
equalsIgnoreCase
Compares this String to another String, ignoring case considerations. Two strings are considered equal ignoring case if they are of the same length and corresponding characters in the two strings are equal ignoring case.
Arguments:
input :: pdk.core.String - the source string.
toCompare :: pdk.core.String - the string to compare.
Result:
output :: pdk.core.Boolean - true if the arguments are not null and they are equivalent ignoring case; false otherwise.
Possible exceptions
NullPointerException - throws if the input or toCompare argument is
NULL
getCommonPrefix
Compares all Strings in an array and returns the initial sequence of characters that is common to all of them.
Example:
A - Array that contains strings 'abcde' and 'abcfg'.
String.getCommonPrefix(A) = 'abc'.
Arguments:
input :: pdk.core.Array<pdk.core.String> - array of String objects, entries may be null.
Result:
output :: pdk.core.String - the initial sequence of characters that are common to all Strings in the array; empty String if the array is null, the elements are all null or if there is no common prefix.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
indexOf
Returns the index within this string of the first occurrence of the specified string.
Arguments:
input :: pdk.core.String - the source string.
searchString :: pdk.core.String - search string.
Result:
output :: pdk.core.Integer - the index of the first occurrence of the second argument in the first argument, or -1 if the string does not occur.
Possible exceptions
NullPointerException - throws if the input or searchString argument is
NULL
indexOfDifference
Compares all Strings in an array and returns the index at which the CharSequences begin to differ. Examples:
A - The array that contains strings: 'abc', 'abd', 'ae'. String.indexOfDifference(A)=1
A - The array that contains strings: 'abc', 'abd', 'abe'. String.indexOfDifference(A)=2
Arguments:
input :: pdk.core.Array<pdk.core.String> - array of char sequences, entries may be null.
Result:
output :: pdk.core.Integer - the index where the strings begin to differ; -1 if they are all equal.
indexOfWithFrom
Returns the index within this string of the first occurrence of the specified string, starting the search at the specified index.
Arguments:
input :: pdk.core.String - the source string
toFind :: pdk.core.String - the search string.
index :: pdk.core.Integer - the starting index
Result:
output :: pdk.core.Integer - the index of the first occurrence of the second argument in the first argument that is greater than or equal to starting index, or -1 if the search string does not occur.
Possible exceptions
NullPointerException - throws if the input, toFind or index argument is
NULL
isEmpty
Returns true if, and only if, length is 0.
Arguments:
input :: pdk.core.String - the source string
Result:
output :: pdk.core.Boolean - true if length is 0, otherwise false
Possible exceptions
NullPointerException - throws if the input argument is
NULL
isNumber
Checks if the String contains only Unicode digits. A decimal point is not a Unicode digit and returns false. null will return false. An empty String (length=0) will return false.
Example:
String.isNumeric(null)=false
String.isNumeric('123')=true
String.isNumeric('12.3')=false
String.isNumeric('-123')=false
Arguments:
input :: pdk.core.String - the string to check, may be null
Result:
output :: pdk.core.Boolean - true if only contains digits, and is non-null.
join
Joins the elements of the provided array into a single String containing the provided list of elements. No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.
Arguments:
input :: pdk.core.Array<pdk.core.String> - the array of values to join together, may be null.
separator :: pdk.core.String - the separator character to use.
Result:
output :: pdk.core.String - the joined String, null if null array input.
lastIndexOf
Returns the index within this string of the last occurrence of the specified string.
Arguments:
input :: pdk.core.String - the source string.
searchString :: pdk.core.String - search string.
Result:
output :: pdk.core.Integer - the index of the last occurrence of the second argument in the first argument, or -1 if the search string does not occur.
Possible exceptions
NullPointerException - throws if the input or searchString argument is
NULL
lastIndexOfWithFrom
Returns the index within the first argument string of the last occurrence of the second argument string, searching backward starting at the specified index.
Arguments:
input :: pdk.core.String - the source string
toFind :: pdk.core.String - the search string.
fromIndex :: pdk.core.Integer - the index to start the search from. There is no restriction on the value of fromIndex. If it is greater than or equal to the length of the source string, it has the same effect as if it were equal to one less than the length of the source string: the second argument string may be searched. If it is negative, it has the same effect as if it were -1: -1 is returned.
Result:
output :: pdk.core.Integer - the index of the last occurrence of the second argument in the first argument, or -1 if the search string does not occur.
Possible exceptions
NullPointerException - throws if the input, toFind or index argument is
NULL
length
Returns the length of the string.
Arguments:
input :: pdk.core.String - the source string
Result:
output :: pdk.core.Integer - the length of the string.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
matches
Tells whether or not this string matches the given regular expression.
Arguments:
input :: pdk.core.String - the source string.
regexp :: pdk.core.String - the regular expression to which the source string is to be matched.
Result:
output :: pdk.core.Boolean - true if, and only if, the first argument string matches the given regular expression.
Possible exceptions
NullPointerException - throws if the input or regexp argument is
NULL
replace
Returns a new string resulting from replacing all occurrences of oldString in this string with newString.
Arguments:
input :: pdk.core.String - the source string.
toBeReplace :: pdk.core.String - the string to be replaced for.
replacing :: pdk.core.String - the replacing string.
Result:
output :: pdk.core.String - a string derived from first argument String by replacing every occurrence of the second argument string with the third argument string.
Possible exceptions
NullPointerException - throws if the input, toBeReplace or replacing argument is
NULL
replaceFirst
Replaces the first substring of this string that matches the given regular expression with the given replacement.
Arguments:
input :: pdk.core.String - the source string.
regexp :: pdk.core.String - the regular expression to which this string is to be matched.
replacing :: pdk.core.String - the string to be substituted for the first match.
Result:
output :: pdk.core.String - the resulting String.
Possible exceptions
NullPointerException - throws if the input, regexp or replacing argument is
NULL
replaceAll
Replaces each substring of this string that matches the given regular expression with the given replacement.
Arguments:
input :: pdk.core.String - the source string.
regexp :: pdk.core.String - the regular expression to which this string is to be matched.
replacing :: pdk.core.String - the string to be substituted for the first match.
Result:
output :: pdk.core.String - the resulting String.
Possible exceptions
NullPointerException - throws if the input, regexp or replacing argument is
NULL
repeat
Returns a string whose value is the concatenation of this string repeated count times. If this string is empty or count is zero then the empty string is returned.
Arguments:
input :: pdk.core.String - the source string.
count :: pdk.core.Integer - number of times to repeat.
Result:
output :: pdk.core.String - string composed of this string repeated count times or the empty string if this string is empty or count is zero.
Possible exceptions
NullPointerException - throws if the input or count argument is
NULL
reverse
Reverses a String.
Arguments:
input :: pdk.core.String - the String to reverse, may be null.
Result:
output :: pdk.core.String - the reversed String, null if null String input.
split
Splits this string around matches of the given regular expression.
Arguments:
input :: pdk.core.String - the source string.
regexp :: pdk.core.Integer - the delimiting regular expression.
Result:
output :: pdk.core.Array<pdk.core.String> - the array of strings computed by splitting the source string around matches of the given regular expression.
Possible exceptions
NullPointerException - throws if the input or regexp argument is
NULL
startWith
Tests if this string starts with the specified suffix.
Arguments:
input :: pdk.core.String - the source string.
prefix :: pdk.core.String - the prefix string.
Result:
output :: pdk.core.Boolean - true if the character sequence represented by the second argument is a prefix of the character sequence represented by the first argument string; false otherwise. Note also that true will be returned if the prefix string is an empty string or is equal to the source string.
Possible exceptions
NullPointerException - throws if the input or prefix argument is
NULL
substringTillEnd
Returns a new string that is a substring of this string from start index till the end.
Arguments:
input :: pdk.core.String - the source string.
index :: pdk.core.Integer - the beginning index, inclusive.
Result:
output :: pdk.core.String - the specified substring.
Possible exceptions
NullPointerException - throws if the input or index argument is
NULL
substring
Returns a new string that is a substring of this string.
Arguments:
input :: pdk.core.String - the source string.
startIndex :: pdk.core.Integer - the beginning index, inclusive.
endIndex :: pdk.core.Integer - the ending index, exclusive.
Result:
output :: pdk.core.String - the specified substring.
Possible exceptions
NullPointerException - throws if the input, startIndex or endIndex argument is
NULL
symbolAt
Returns the character at the specified index.
Arguments:
input :: pdk.core.String - the source string.
index :: pdk.core.Integer - the index.
Result:
output :: pdk.core.String - the char value at the specified index of this string. The first char value is at index 0.
Possible exceptions
NullPointerException - throws if the input or index argument is
NULL
toLowerCase
Converts all of the characters in this String to lower case.
Arguments:
input :: pdk.core.String - the source string.
Result:
output :: pdk.core.String - the String, converted to lowercase.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
toUpperCase
Converts all of the characters in this String to uppercase.
Arguments:
input :: pdk.core.String - the source string.
Result:
output :: pdk.core.String - the String, converted to uppercase.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
trim
Returns a copy of the string, with leading and trailing whitespace omitted.
Arguments:
input :: pdk.core.String - the source string.
Result:
output :: pdk.core.String - a copy of the source string with leading and trailing white space removed, or this string if it has no leading or trailing white space.
Possible exceptions
NullPointerException - throws if the input argument is
NULL
uncapitalize
Uncapitalizes a String, changing the first character to lower case as per Character.toLowerCase(int). No other characters are changed.
Example:
String.uncapitalize('TeST') will return 'teST'.
Arguments:
input :: pdk.core.String - the String to uncapitalize, may be null.
Result:
output :: pdk.core.String - the uncapitalized String, null if null String input.
wrap
Wraps a String with another String.
Example:
String.wrap('some', 'x')='xsomex'
Arguments:
input :: pdk.core.String - the String to be wrapper, may be null.
wrap :: pdk.core.String - the String that will wrap str.
Result:
output :: pdk.core.String - wrapped String, null if null String input.
Possible exceptions
NullPointerException - throws if the input or wrap argument is
NULL
Last updated