Reputation: 1780
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
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+')';
}
Upvotes: 3
Reputation: 1780
I found the solution , is to use this code
print(sana.replaceAll(" ", ""));
so the space between Harun and ) disappear
Upvotes: 1