从 flutter/dart 中的字符串中删除不可打印的字符

use*_*135 0 dart flutter

如何从 Flutter/Dart 中的字符串中删除不可打印的字符。

\n
var c ="Maintain central project files (hard copy and electronic) for administration.\xc3\xa2\xc2\xa2Perform a wide variety of administrative duties"\n
Run Code Online (Sandbox Code Playgroud)\n

感谢您的帮助

\n

Did*_*ete 6

如果你只想保留基本的 ASCII 字符,你可以尝试这样的事情:

\n
  var c =\n      "Maintain central project files (hard copy and electronic) for administration.\xc3\xa2\xc2\xa2Perform a wide variety of administrative duties";\n  var clean = c.replaceAll(RegExp(r'[^A-Za-z0-9().,;?]'), ' ');\n  print(clean);\n
Run Code Online (Sandbox Code Playgroud)\n

你得到:

\n
Maintain central project files (hard copy and electronic) for administration.  Perform a wide variety of administrative duties\n
Run Code Online (Sandbox Code Playgroud)\n

调整正则表达式以包含更多或更少的字符,具体取决于您想要的清理量(假设您可以删除所有标点符号等......)

\n