Sana'a Al-ahdal
Sana'a Al-ahdal

Reputation: 1780

delete whitespace from the end of string in dart

please I want to know how to delete whitespaces from the end of string in dart . ex :

String name ="(  Sana .  Harun  )";

when I use this code

print(sana.replaceAll(new RegExp(r"\s+\b|\b\s"),""));

it just delete from the beggining and not from the end , and print Like this :(Sana.Harun ) .. there is a space between Harun and ) . I want to delete the space between Harun and )

Can any one help me , please ?

Upvotes: 1

Views: 2394

Answers (2)

Naveen Avidi
Naveen Avidi

Reputation: 3073

Call this function/method !

String getWithoutSpaces(String s){
      String tmp = s.substring(1,s.length-1);
      while(tmp.startsWith(' ')){
       tmp = tmp.substring(1);
      }
      while(tmp.endsWith(' ')){
       tmp = tmp.substring(0,tmp.length-1);
      }

  return '('+tmp+')';
}

pic

Upvotes: 3

Sana'a Al-ahdal
Sana'a Al-ahdal

Reputation: 1780

I found the solution , is to use this code

print(sana.replaceAll(" ", ""));

so the space between Harun and ) disappear

Upvotes: 1

Related Questions