Reputation: 86
I have a text
String text = "abcd.."
and
String text2 = "abcd...."
I want to write a function and output "abcd."
like
function(String string){
//codes
return string // string must be "abcd." here
}
Upvotes: 1
Views: 55
Reputation: 163632
If all occurrences of 2 or more dots should be replaced, you could use replaceAll with a pattern \.{2,}
to match 2 or more dots and replace with a single dot.
String stripDots(String string){
return string.replaceAll(RegExp(r'\.{2,}'), '.');
}
String text = "abc.... Def..";
print(stripDots(text));
Output
abc. Def.
Upvotes: 3