乐闻世界logo
搜索文章和话题

How to Remove All Spaces from a String in Dart?

2月7日 11:35

In Dart, you can use the replaceAll method to remove all spaces from a string. This method allows you to specify a pattern (a space) and a replacement value (an empty string). Below is a specific example of how to implement it:

dart
void main() { String originalString = "这 是 一 个 测试 字 符 串"; String stringWithoutSpaces = originalString.replaceAll(' ', ''); print(stringWithoutSpaces); // Output: This is a test string }

In this example, replaceAll(' ', '') replaces all spaces in the string with an empty string, thereby removing all spaces.

标签:Dart