关于flutter:如何在Dart中删除字符串的所有空白?

How to remove all whitespace of a string in Dart?

使用trim()消除Dart中的空白,它不起作用。
我做错了什么或有其他选择吗?

1
2
3
       String product ="COCA COLA";

       print('Product id is: ${product.trim()}');

控制台打印:Product id is: COCA COLA


尝试这个

1
2
String product ="COCA COLA";
print('Product id is: ${product.replaceAll(new RegExp(r"\s+\b|\b\s"),"")}');


Trim方法只删除开头和结尾。 使用Regexp实例:
这是一个例子:
Dart:使用regexp从字符串中删除空格


使用修剪功能

1
2
String name ="Stack Overflow";
print(name.trim());