Safe
The Strings package provides null safe wrappers for each of the String methods.
Generally, the Safe methods convert a null String? to an empty String before passing the string to the wrapped String method.
In some cases we do additional processing to avoid RangeExceptions and other problems caused by an empty String. These exceptions are noted below.
length
Refer to String.length
codeUnits
Refer to String.codeUnits
runes
Refer to String.runes
compareTo
The compareTo method returns two Strings returning 1, 0 or -1.
If both string
and other
are null then -1 is returned.
If one of string
and other
are null then -1 or ` is returned based on 'nullIsLessThan'.
If nullIsLessThan is true than null is treated as less than all other strings.
If nullIsLessThan is false then null is treated as greater than all other strings.
contains
Refer to String.contains
endsWith
Refer to String.endsWith
indexOf
Refer to String.indexOf
lastIndexOf
Refer to String.lastIndexOf
matchAsPrefix
padLeft
Refer to String.padLeft
padRight
Refer to String.padRight
replaceAll
Refer to String.replaceAll
replaceAllMapped
Refer to String.replaceAllMapped
replaceFirst
Refer to String.replaceFirst
replaceFirstMapped
Refer to String.replaceFirstMapped
replaceRange
Refer to String.replaceRange
split
Refer to String.split
splitMapJoin
Refer to String.splitMapJoin
startsWith
Refer to String.startsWith
substring
Refer to String.substring
The Strings version of substring has special handling of a null string argument.
Instead of replacing it with an empty string we return a string containing spaces of the length required to fulfill the requested start/end index. If end is not passed then we return a single space.
toLowerCase
Refer to String.toLowerCase
toUpperCase
Refer to String.toUpperCase
trim
Refer to String.trim
trimLeft
Refer to String.trimLeft
trimRight
Refer to String.trimRight
Last updated