使用trim()消除达特白色空间,这是行不通的。我做错了什么或有其他选择吗?
trim()
String product = "COCA COLA"; print('Product id is: ${product.trim()}');
控制台打印: Product id is: COCA COLA
Product id is: COCA COLA
试试这个
String product = "COCA COLA"; print('Product id is: ${product.replaceAll(new RegExp(r"\s+\b|\b\s"), "")}');
更新:
String name = '4 ever 1 k g @@ @'; print(name.replaceAll(new RegExp(r"\s+"), ""));