0
votes

I am accepting values from textfield and want to remove multiple whitespaces from those values and replace them with single one how can I achieve this in dart so far I have tried,

' '.join(mystring.split())

but this seems not to work as it does in python it throws join cannot be performed on string So how can I do it in dart...

1

1 Answers

0
votes

Something like:

final newstring = yourstring.replaceAllMapped(RegExp(r'\b\s+\b'), (match) {
  return '"${match.group(0)}"';
});

or

final newstring = yourstring.replaceAllMapped(new RegExp(r'/\s+/'), (match) {
  return ' ';
});