kat*_*tre 1 string replaceall dart
String text = "replace all characters" --> 22 characters
text.replaceAll(RegExp('.'), '*');
// result -> ********************** --> 22 characters
Run Code Online (Sandbox Code Playgroud)
这样一来,所有的人物都发生了变化。如何排除空格字符。
// I want it this
// result -> ******* *** ********** -> Characters 8 and 13 are empty.
Run Code Online (Sandbox Code Playgroud)
你想要的是负匹配:
void main() {
String text = "replace all characters";
print(text.replaceAll(RegExp('[^ ]'), '*'));
// ******* *** **********
}
Run Code Online (Sandbox Code Playgroud)
[^ ]将匹配除空格之外的任何字符。
| 归档时间: |
|
| 查看次数: |
938 次 |
| 最近记录: |