String Methods

Use Primavera Cloud Expression Language supported string methods to manipulate textual data.

Refer to the official Java documentation for more information on each method.

Notes:

String Methods

Method Signature

Description

Parameters

Example

String.codePointAt(Int index)

Returns the Unicode code point value for the character within the string at the index matching the Int passed as an argument.

Int index - Index value of a string character.

"Hello".codePointAt(1); //returns 101, the Unicode code point value of "e"

String.codePointBefore(Int index)

Returns the Unicode code point value for the character within the string at the index value immediately before the Int passed as an argument.

Int index - Index value of a string character.

"Hello".codePointBefore(1); //returns 72, the Unicode code point value of "H"

String.codePointCount(Int indexStart, Int indexEnd)

Returns the number of Unicode code points within an index range specified by the Int values passed as arguments.

Int indexStart - Value to specify the start of an index range. The number of Unicode points within the specified range is returned by this method.

Int indexEnd - Value to specify the end of an index range.

"Hello".codePointCount(1, 4); //returns 3, the number of character in the index range 1 to 4, namely "ell";

String.compareTo(String string)

Compares the lexicographic value of a String to the String value passed as an argument. Returns 0 if the Strings are lexicographically equivalent. Returns a value greater than 0 if the argument String is lexicographically greater, returns a value less than 0 if the argument String is lexicographically lesser. Lexicographic equivalence is based on the order of strings in a lexicon or dictionary. For example, "ant" is lexicographically lesser than "bat" because ant occurs first in an alphabetically ordered lexicon.

String string - String to lexicographically compare with the String calling the compareTo method.

"Hello".compareTo("Goodbye"); //returns a value greater than 0 because "Hello" occurs after "Goodbye" in an ordered dictionary.

"Hello".compareTo("Hello"); //returns 0 because "Hello" and "Hello" are lexicographically equivalent; they occupy the same position in an ordered lexicon or dictionary.

"Hello".compareTo("hello"); //returns a value less than 0 because "Hello" occurs before "hello" in an ordered lexicon or dictionary; all capital letter forms precede their lowercase counterparts.

String.compareToIgnoreCase(String string)

Compares the lexicographic value of a String to the String value passed as an argument and ignores differences in case. Returns 0 if the Strings are lexicographically equivalent. Returns a value greater than 0 if the argument String is lexicographically greater, returns a value less than 0 if the argument String is lexicographically lesser.

Note: Lexicographic equivalence is based on the order of strings in a lexicon or dictionary. For example, "ant" is lexicographically lesser than "bat" because ant occurs first in an alphabetically ordered lexicon.

String string - String to lexicographically compare with the String calling the compareToIgnoreCase method.

"Hello".compareToIgnoreCase("hello"); //returns 0.

String.contains(String string)

Returns a Boolean value indicating whether the String passed as an argument appears within the String calling the contains method.

String string - String to find within the String calling the contains method.

"Hello".contains("lo"); //returns true

"Hello".contains("World"); //returns false

String.endsWith(String string)

Returns a Boolean value indicating whether the String calling the endsWith method ends with the String passed as an argument.

String string - String to find at the end of the String calling the endsWith method.

"Hello".endsWith("lo"); //returns true

"Hello".endsWith("He"); //returns false

String.equalsIgnoreCase(String string)

Returns a Boolean indicating whether the String passed as an argument is equal to the String calling the equals method ignoring case. Strings are equivalent if they are a representation of the same sequence of characters.

String string - String to check against the String calling the equalsIgnoreCase method.

"Hello".equalsIgnoreCase("hello"); //returns true

String.hashCode()

Returns a numeric hash code value representing the String calling the hashCode method.

No method parameters.

"Hello".hashCode(); //returns 69609650

String.lastIndexOf(String string)

Returns the last index value at which the String passed as an argument occurs in the String calling the lastIndexOf method.

String string - String to find the index of the last occurrence of in the String calling the lastIndexOf method.

"Hello".lastIndexOf("l"); //returns 3

String.length()

Returns the length of the String calling the length method.

No method parameters.

"Hello".length(); //returns 5

String.replace(String stringToFind, String stringToReplace)

Replaces occurrences of the first String passed as an argument in the String calling the method with the second String passed as an argument.

String stringToFind - String to find within the String calling the replace method.

String stringToReplace - String to use to replace the String passed as the first argument to the method.

"Hello World".replace("World", "Universe!"); //returns "Hello Universe!"

 

String.startsWith(String string)

Returns a Boolean value indicating whether the String calling the startsWith method starts with the String passed as an argument.

String string - String to find at the end of the String calling the startsWith method.

"Hello".startsWith("He"); //returns true

String.substring(Int index)

Returns a substring of the String calling the substring method. The resulting substring begins with the character stored at the String index location matching the passed Int argument and ends with the last character of the String.

Int index - Index value specifying where to begin extracting the substring from the String calling the substring method.

"Hello".substring(2); //returns "llo"

String.toLowerCase()

Returns the result of converting all of the characters of the String calling the toLowerCase method to their lowercase form.

No method parameters.

"Hello".toLowerCase(); //returns "hello"

String.toUpperCase()

Returns the result of converting all of the characters of the String calling the toUpperCase method to their uppercase form.

No method parameters.

"Hello".toUpperCase(); //returns "HELLO"

String.trim()

Returns the result of removing space characters that appear at the beginning or the end of the String calling the trim method.

No method parameters.

" Hello World ".trim(); //returns "Hello World"

Additional String Methods

Method Signature

Description

Parameters

Examples

String.concat(String string)

Returns the concatenation of the String passed as an argument and the String calling this method.

String string - A value of type String to append to the end of the String calling the method.

"Hello".concat(" World"); //returns "Hello World"

String.equals(Object obj)

Returns the result of comparing the String calling this method to the object passed as an argument. Returns true if the Object value passed as an argument represents a String equivalent to the String calling the method, otherwise returns false.

Object object - An Object against which the String calling the method is compared.

"Hello".equals("Hello"); //returns true.

"Hello".equals("World"); // returns false.

String.indexOf(Int character)

Returns the indexical position of the specified character value in the String calling this method. Arguments may be passed as a literal quote enclosed character or as a Unicode code point Integer representing that character.

Int character - A value of type Int in Unicode code point format representing an alphanumeric character.

"Hello".indexOf("H"); //returns 0

"Hello".indexOf(72); //returns 0

"Hello".indexOf("i"); //returns -1

"Hello".indexOf(105); //returns -1

String.isEmpty()

Returns true if the length of the string calling the method is equal to 0, otherwise returns false.

No method parameters.

"Hello".isEmpty(); //returns false

"".isEmpty(); //returns true

String.offsetByCodePoints(Int index, Int codePointOffset)

Returns the index within the String calling this method that is offset from the index argument by the number of code points specified by the codePointOffset argument.

Int index - Initial index value within the Strign calling this method.

Int codePointOffset - Number of points to offset from the index argument.

"Hello".offsetByCodePoints(1, 2); //returns 3

String.toString()

Returns the String calling this method.

No method parameters.

"Hello".toString(); //returns "Hello"

String.valueOf(Object obj)

Returns the string representation of the Object passed as an argument.

Object obj - An object to convert to a String value.

String.valueOf(3); //returns "3"



Last Published Tuesday, May 21, 2024