StringCustomFunctionExtensions extension
String common function extensions
- on
Properties
- capitalize → String
-
Capitalizes the first letter of the string.
Returns the original string if it is empty.
no setter
- removeAllSpaces → String
-
Removes all spaces from the string.
no setter
- reversed → String
-
Reverses the string.
no setter
Methods
-
insert(
int index, String str) → String -
Inserts the string
str
at the specifiedindex
within the original string. Throws RangeError ifindex
is out of bounds. -
onEmpty(
String? val) → String? -
Returns a provided alternative string
val
if the original string is empty. Ifval
is null, it defaults to an empty string. -
repeat(
int times) → String -
Repeats the string
times
number of times. -
replaceFirst(
String from, String replace) → String -
Replaces the first occurrence of the substring
from
withreplace
. Iffrom
is not found in the string, returns the original string. -
replaceLast(
String from, String to) → String -
Replaces the last occurrence of the substring
from
withto
. Iffrom
is not found in the string, returns the original string. -
toEnum<
T> (List< T> enumValues) → T? -
Tries to parse the string into a specified enum type
T
. Returns null if the parsing fails. This method requires the list of all enum valuesenumValues
to check against.