I have a 'textformfeild' that takes strings and I want to trim the white spaces at the begining and the end and strict the one in the middle to only one space.
for example if my string is like this:(....AB....CD.....) where the black dots represent the white spaces.
and I wanna make it look like this:(AB.CD)
any idea on how to do that? this is what I tried to do:
userWeight!.trim()
but this will remove all the white spaces including the one in the middle
trim
will remove left and right spaces. You can use RegExp to remove inner spaces:
void main(List<String> args) {
String data = " AB CD ";
String result = data.trim().replaceAll(RegExp(r' \s+'), ' ');
print(result); //AB CD
}