关于解析文本中空格的坑-部分空格不能识别

2020-05-06  本文已影响0人  Jesscia_Liu

1、场景描述

目前做一款教育软件涉及到文本解析需要读取txt文件中的文本,然后按照用空格进行筛选。
然鹅,读取字符串后使用空格对字符串进行分割时,遇到了个别空格不能识别的问题。

2、问题拓展

The non-breaking space (U+00A0 Unicode, 160 decimal, ) is not the same as the space character (U+0020 Unicode, 32 decimal). Well, both of them seems to be a “space”, but they are absolutely different characters.

3、问题解决

var s = ' ' // 假设这里是一个160的空格。
var reg = new RegExp(String.fromCharCode(160),"gm");
var 32sp = String.fromCharCode(32)
s = s.replace(reg, 32sp);

【参考文献】

不同unicode编码的空格挖的坑

上一篇 下一篇

猜你喜欢

热点阅读