javascript - 使用 Node.js 处理 TXT 文件中的非法字符(撇号)
问题描述
我依赖在 Node.js 中从外部发送的 .txt 文件,这些文件有时会包含我将其归类为“非法”字符的内容,例如撇号和逗号,从而导致从网页和程序(例如 Microsoft Word)复制和粘贴
如何获取 Node.js 或使用 Javascript 来替换这些不正确的格式,例如用正确格式的撇号替换撇号或去掉任何非法字符句号?
这是来自网页的示例,并显示在 PasteBin 中:
Resilience is what happens when we’re able to move forward even when things don’t fit together the way we expect.
And tolerances are an engineer’s measurement of how well the parts meet spec. (The word ‘precision’ comes to mind). A 2018 Lexus is better than 1968 Camaro because every single part in the car fits together dramatically better. The tolerances are more narrow now.
One way to ensure that things work out the way you hope is to spend the time and money to ensure that every part, every form, every worker meets spec. Tighten your spec, increase precision and you’ll discover that systems become more reliable.
The other alternative is to embrace the fact that nothing is ever exactly on spec, and to build resilient systems.
You’ll probably find that while precision feels like the way forward, resilience, the ability to thrive when things go wrong, is a much safer bet.
The trap? Hoping for one, the other or both but not doing the work to make it likely. What will you do when it doesn’t work?
Neither resilience nor tolerances get better on their own.
从以下 URL 复制并粘贴到记事本中并保存
解决方案
您可以使用RegExp删除不需要的字符
// text is the pasted text
var filtered = text.replace(/[',]/gm, '');
推荐阅读
- java - 如何等待在 android 中更改不同的图像视图?
- ios - 我可以在 iOS 中使用 Google Oboe 或 AAudio 吗?https://github.com/google/oboe
- javascript - 在全局 ajaxForm 的每个实例中使用 beforeSend 和 complete
- python - 如何使用 python selenium 在 chrome 浏览器上单击下载图标
- r - 如何选择已以升序方式在其他行中排序的特定行?
- android - Android 依赖 'androidx.core:core' 有不同版本的编译(1.0.0-rc01)和运行时(1.0.2)类路径
- javascript - Javascript:即使不满足 IF 语句的所有条件,也会继续显示错误
- java - 我的 java SSHClient 类有问题,特别是 Expect 方法没有按预期返回数据,会发生什么?
- .net - 将日志文件输出发送到控制台
- android - 如何解决“被 Play Protect 屏蔽”的问题