如何在Dart中删除字符串的所有空格? [英] How to remove all whitespace of a string in Dart?
本文介绍了如何在Dart中删除字符串的所有空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 trim()
消除Dart中的空白,并且不起作用。
我在做什么错还是有其他选择?
Using trim()
to eliminate white space in Dart and it doesn't work.
What am I doing wrong or is there an alternative?
String product = "COCA COLA";
print('Product id is: ${product.trim()}');
控制台打印:产品编号是:可口可乐
推荐答案
尝试一下
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+"), ""));
这篇关于如何在Dart中删除字符串的所有空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文