Home > Net >  how to replace multiple whitespaces with single whitespace in Dart and Flutter
how to replace multiple whitespaces with single whitespace in Dart and Flutter

Time:09-24

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...

CodePudding user response:

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 ' ';
});

CodePudding user response:

def clean_words(Complex_words):
    List_words =Complex_words.split()
    New_word = ""
    for i in List_words:
        New_word = New_word   " "  i

    return New_word
  • Related