Using trim()
to eliminate white space in Dart and it doesn\'t work.
What am I doing wrong or is there an alternative?
String product = \"COC
In case this is of any help to someone in the future, for convenience you can define an extension method to the String class:
extension StringExtensions on String {
String removeWhitespace() {
return this.replaceAll(' ', '');
}
}
This can be called like product.removeWhiteSpace()
I've used it in the past to create a helper method when sorting lists by a string whilst ignoring case and whitespace
extension StringExtensions on String {
String toSortable() {
return this.toLowerCase().replaceAll(' ', '');
}
}