使用Node.js处理TXT文件中的非法字符(撇号)

时间:2019-03-18 17:29:28

标签: javascript node.js node-modules

我依靠的是在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.

https://pastebin.com/uJ7GAKk4

从以下URL复制并粘贴到记事本中并保存

https://seths.blog/storyoftheweek/

1 个答案:

答案 0 :(得分:0)

您可以使用RegExp删除不需要的字符

// text is the pasted text
var filtered = text.replace(/[',]/gm, '');