PingOne

String library

You can perform string-related operations within an expression using the following library.

String Description Input Output

boolean isNotEmpty(String <input>)

where <input> is the string to check.

Returns true if the input string is not empty ("") and not null.

  1. #string.isNotEmpty('InputData')

  2. #string.isNotEmpty('')

  1. true

  2. false

boolean isNotBlank(String <input>)

where <input> is the string to check.

Returns true if the input string is not empty (""), not null and not white space only.

  1. #string.isNotBlank('InputData')

  2. #string.isNotBlank(' ')

  1. true

  2. false

String upperCase(String <input>)

where <input> is the string being converted to upper case.

Converts all characters to uppercase. Returns all characters in upper case if input is not null. Returns null if input is null.

#string.upperCase('john')

JOHN

String lowerCase(String <input>)

where <input> is the string being converted to lower case.

Converts all characters to lowercase. Returns all characters in lower case if input is not null. Returns null if input is null.

#string.lowerCase('LOWER')

lower

String trim(String <input>)

where <input> is the string being trimmed.

Removes white space from the start and end of string if input is not null. Returns null if input is null.

#string.trim(' No Padding ')

No Padding

String substring(String <input>, int <start>, int <end>)

where:

  • <input> is the string to get the substring from

  • <start> is the position to start from

  • <end> is the exclusive position to end at

Gets a substring from the input string starting from the start position and up until the end position, not including the end position. You can use a negative value to start or end n characters from the end of the string. All position counting is zero-based. If start is not to the left of end, "" is returned. Returns null if input is null.

  1. #string.substring('example input for substring demo', 8, 13)

  2. #string.substring('example input for substring demo', -24, 13)

  3. #string.substring('example input for substring demo', -24, -19)

  1. input

  2. input

  3. input

boolean startsWith(String <input>, String <prefix>)

where:

  • <input> is the string to check

  • <prefix> is the prefix to match at the start of the input string.

Checks if the input string starts with the specified prefix and the comparison is case sensitive. Returns true if the input string starts with the prefix with the same case or if both are null.

#string.startsWith('InputData', 'In')

true

boolean endsWith(String <input>, String <suffix>)

where:

  • <input> is the string to check

  • <suffix> is the suffix to match at the end of the input string

Checks if the input string ends with the specified suffix and the comparison is case sensitive. Returns true if input string ends with the suffix with the same case or if both are null.

#string.endsWith('InputData', 'Data')

true

String[] split(String <input>, String <separators>)

where:

  • <input> is the string to split

  • <separators> are the characters to be used as delimiters to split the input string

Splits the provided text into an array based on the specified separators. Returned array won’t contain any separators. A null separator splits on white space. Returns null if input is null.

#string.split('Administrator, User, Guest', ', ')

["Administrator", "User", "Guest"]

String join(Array <values>, String <separator>)

where:

  • <values> is the array containing the values to be joined.

  • <separator> is the delimiter to use when joining the values in the input array. A null separator is treated as an empty string.

Joins the elements of the provided array into a single string containing the provided elements separated by the provided separator. Returns the joined string or null if the array is null.

#string.join(\{'Administrator', 'User', 'Guest'}, ', ')

Administrator, User, Guest

int indexOf(String <input>, String <searchStr>, int <fromIndex>)

where:

  • <input> is the string to search against

  • <searchStr> is the string to find

  • <fromIndex> is the start position in the input string to start the search from

Finds the first index of the search string within the input string. A negative start position is treated as zero, and a start position greater than the input string length only matches an empty search. An empty search string ("") always matches. Returns -1 if a match is not found.

#string.indexOf('To find and return index or return -1', 'return', -1)

12

int lastIndexOf(String <input>, String <searchStr>, int <fromIndex>)

where:

  • <input> is the string to search against

  • <searchStr> is the string to find

  • <fromIndex> is the start position in the input string to begin the search from

Finds the last index within the input string. Search starts from the start position and continues backwards. A negative start position is treated as zero, and a start position greater than the input string length searches the entire string backwards. Returns -1 if a match is not found.

#string.lastIndexOf('To find and return index or return -1', 'return', 50)

28

int length(String <input>)

where <input> is the string to find the length of.

Returns the length of the input string or 0 if input is null.

#string.length('Input')

5

String replace(String <input>, String <searchStr>, String <replacement>, int <max>)

where:

  • <input> is the string to be searched against to be replaced in.

  • <searchStr> is the string to be matched and replaced.

  • <replacement> is the string to be replaced with.

  • <max> is the maximum number of times replacement should be done. If -1, all matched values will be replaced.

Replaces all occurrences of searchStr within input according to the replacement and max values. A null reference passed to this method is a no-op.

#string.replace('input values replaced by input replacement', 'in', 'out', -1)

output values replaced by output replacement

int compare(String <str1>, String <str2>, boolean <ignoreCase>)

where:

  • <str1> is the string to compare against

  • <str2> is the string to compare

  • <ignoreCase> determines whether the comparison is case-sensitive.

Compares two strings lexicographically. Returns 0 if str1 is equal to str2 or both are null. Returns a negative number if str1 is less than str2. Returns a positive number if str1 is greater than str2.

#string.compare('Input', 'INPUT', true)

0

Number asInt(String <input>, Number <defaultIfNullOrInvalid>)

where:

  • <input> is the string representation of an integer number

  • <defaultIfNullOrInvalid> is the default value to be used if the string input is null, not a valid number, or out of range for integers

Parses the string argument as a signed decimal integer (min -2147483648 and max 2147483647).

The characters in the string must all be decimal digits, except that the first character can be an ASCII minus sign (-) to indicate a negative value or an ASCII plus sign (+) to indicate a positive value. If input is null or not a valid integer, defaultIfNullOrInvalid is returned.

  1. #string.asInt('12', 0)

  2. #string.asInt('NaN', 0)

  3. #string.asInt('9876543210123456789', 0)

  1. 12

  2. 0

  3. 0

Number asLong(String <input>, Number <defaultIfNullOrInvalid>)

where:

  • <input> is the string representation of a Long number

  • <defaultIfNullOrInvalid> is the default value to be used if string input is null, not a valid number, or out of range for Longs

Parses the string argument as a signed decimal long (min -9223372036854775808 and max 9223372036854775807).

The characters in the string must all be decimal digits, except that the first character can be an ASCII minus sign (-) to indicate a negative value or an ASCII plus sign (+) to indicate a positive value. If input is null or not a valid Long, defaultIfNullOrInvalid is returned.

  1. #string.asLong('12', 0)

  2. #string.asLong('NaN', 0)

  3. #string.asLong('9876543210123456789', 0)

  1. 12

  2. 0

  3. 0

Number asBigInt(String <input>, Number <defaultIfNullOrInvalid>)

where:

  • <input> is the string representation of a BigInteger number

  • <defaultIfNullOrInvalid> is the default value to be used if string input is null, not a valid number, or out of range for BigInteger

Translates the decimal string representation of a BigInteger into a BigInteger.

The string representation consists of an optional minus sign followed by a sequence of one or more decimal digits. The character-to-digit mapping is provided by Character.digit. If input is null or not a valid Big Integer, defaultIfNullOrInvalid is returned.

  1. #string.asBigInt('1234567890987654321', 0)

  2. #string.asBigInt('NaN', 0)

  1. 1234567890987654321

  2. 0

Number asFloat(String <input>, Number <defaultIfNullOrInvalid>)

where:

  • <input> is the string representation of a Float number

  • <defaultIfNullOrInvalid> is the default value to be used if string input is null, not a valid number, or out of range for Floats

Parses the string argument as a signed decimal float. If input is null, not a valid Float, or Infinity, defaultIfNullOrInvalid is returned.

  1. #string.asFloat('12.5', 0)

  2. #string.asFloat('NaN', 0)

  3. #string.asFloat('1234567899876543210123456789987654321019.12', 0)

  1. 12.5

  2. 0

  3. 0

Number asDouble(String <input>, Number <defaultIfNullOrInvalid>)

where:

  • <input> is the string representation of a Double number

  • <defaultIfNullOrInvalid> is the default value to be used if string input is null, not a valid number, or out of range for doubles

Parses the string argument as a signed decimal double. If input is null, not a valid number within the range of Double, or Infinity, defaultIfNullOrInvalid is returned.

  1. #string.asDouble('1234567899876543210123456789987654321019.12', 0)

  2. #string.asDouble('NaN', 0)

  1. 1234567899876543210123456789987654321019.12

  2. 0

Number asBigDecimal(String <input>, Number <defaultIfNullOrInvalid>)

where:

  • <input> is the string representation of a BigDecimal number

  • <defaultIfNullOrInvalid> is the default value to be used if string input is null, not a valid number, or out of range for BigDecimal

Translates the string representation of a BigDecimal into a BigDecimal.

The string representation consists of an optional sign, (+ or -), followed by a sequence of zero or more decimal digits (the integer), optionally followed by a fraction, optionally followed by an exponent. The fraction consists of a decimal point followed by zero or more decimal digits. The string must contain at least one digit in either the integer or the fraction. The exponent consists of the character e or E followed by one or more decimal digits.

The value of the exponent must lie between -Integer.MAX_VALUE (Integer.MIN_VALUE+1) and Integer.MAX_VALUE, inclusive. If input is null or not a valid BigDecimal, defaultIfNullOrInvalid is returned.

  1. #string.asBigDecimal('1234567890987654321.14', 0)

  2. #string.asBigDecimal('NaN', 0)

  1. 1234567890987654321.14

  2. 0

String asBase64Encoded(String <input>)

where <input> is the string to be encoded.

Encodes the input string into a new string using the Base64 encoding scheme. Returns the encoded string if input is not empty, or else input is returned as-is.

#string.asBase64Encoded('Test Value for encoding')

VGVzdCBWYWx1ZSBmb3IgZW5jb2Rpbmc=

String asBase64Decoded(String <input>)

where <input> is the Base64 encoded string to be decoded.

Decodes a Base64 encoded string into a new string using the Base64 encoding scheme. Returns the encoded string if input is not empty, or else input is returned as-is. This will return null if the input string is not in the valid Base64 schema.

#string.asBase64Decoded('VGVzdCBWYWx1ZSBmb3IgZW5jb2Rpbmc=')

Test Value for encoding

String asUrlEncoded(String <input>)

where <input> is the string to be encoded.

Translates a string into application/x-www-form-urlencoded format using UTF-8 encoding scheme. Returns the encoded string if input is not empty, or else input is returned as-is.

#string.asUrlEncoded('username=johndoe+admin')

username%3Djohndoe%2Badmin

String asUrlDecoded(String <input>)

where <input> is the URL encoded string to be decoded.

Decodes an application/x-www-form-urlencoded string using UTF-8 encoding scheme. Returns the decoded string if input is not empty, or else input is returned as it is. Returns null if the input string cannot be decoded due to any illegal characters.

#string.asUrlDecoded('username%3Djohndoe%2Badmin')

username=johndoe+admin

String format(String <format>, String…​ <args>)

where:

  • <format> is the format supported by java.util.Formatter

  • <args> are the arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and can be zero

Returns a formatted string using the specified format string and arguments. Returns null if a format string contains an illegal syntax, a format specifier that is incompatible with the given arguments, insufficient arguments given the format string, or other illegal conditions.

  1. #string.format('UserId: %s, Full Name: %s, %s', 'johndoe','John', 'Doe')

  2. #string.format('Hex for 10 is %X', 10)

  1. UserId: johndoe, Full Name: John, Doe

  2. Hex for 10 is A

String uuidAsBase64Guid(String <input>, String <defaultIfNullOrInvalid>)

where:

  • <input> is a string representation of a UUID. Invalid if not compatible with regex /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/

  • <defaultIfNullOrInvalid> is the default value to be used if input is null or not a valid UUID

Translates the string representation of a UUID to a GUID in Base64 format. If input is null or not a valid UUID, <defaultIfNullOrInvalid> is returned.

  1. #string.uuidAsBase64Guid('7754d487-1fc3-4206-9e95-ce012f1586e5', null)

  2. #string.uuidAsBase64Guid('invalid', 'lZkqAJgEv0ueGKboT/JFVg==')

  1. h9RUd8MfBkKelc4BLxWG5Q==

  2. lZkqAJgEv0ueGKboT/JFVg==

String firstNonEmpty(String <value1>, String…​ <value2…​10>)

where:

  • <value1> is the input value to test. Can be null or empty

  • <value2…​10> are additional and optional input values to test. Can be null or empty

Returns the first value in the input values which is not empty ('') or null. If all input values are null or empty, then null is returned. There must be at least one input value and the rest are optional. You can enter a maximum of 10 input values.

  1. #string.firstNonEmpty(null, '', 'firstNonEmpty', 'secondNonEmpty')

  2. #string.firstNonEmpty('', '')

  1. firstNonEmpty

  2. null

String firstNonBlank(String <value1>, String…​ <value2…​10>)

where:

  • <value1> is the input value to test. Can be null, empty or blank.

  • <value2…​10> are additional and optional input values to test. Can be null, empty or blank

Returns the first value in the input values which is not empty (''), null or whitespace only. If all input values are null, empty or blank then null is returned. There must be at least one input value and the rest are optional. You can enter a maximum of 10 input values.

  1. #string.firstNonBlank(null, '', ‘ ‘, 'firstNonEmpty', 'secondNonEmpty')

  2. #string.firstNonBlank('', ‘ ‘, '')

  1. firstNonEmpty

  2. null