どうも、ちょげ(@chogetarou)です。
文字列内の空白を全削除する方法を紹介します。
方法

文字列から空白を削除するには、文字列のreplaceAllメソッドを使います。
まず、文字列からreplaceAllメソッドを呼び出します。
そして、replaceAllメソッドの第1引数に「RegExp(r”\s+”)」、第2引数に「”」を指定します。
str.replaceAll(RegExp(r"\s+"), '');
replaceAllメソッドは、空白を全て削除した文字列を返します。
使用例
void main() {
var greeting = 'H e l l o, W o r l d.';
greeting = greeting.replaceAll(RegExp(r"\s+"), '');
print(greeting); //Hello,World.
}
コメント