简体   繁体   English

“和”的区别

[英]Difference between “ and "

I'm building an angular 2 application similar to typing test.我正在构建一个类似于打字测试的 angular 2 应用程序。 There's a text and user needs to type that out.有一个文本,用户需要输入它。 I am comparing every typed word with the corresponding word in the text.我将每个输入的单词与文本中的相应单词进行比较。

The word “collection (with the inverted comma) can't be compared as it is never equals to "collection (with inverted comma) . Couldn't find anything on google and SO. “collection (带引号) 这个词不能比较,因为它永远不等于“collection(带引号)”。在谷歌和SO上找不到任何东西。

Here's a image reference from augury.这是来自augury的图像参考。 在此处输入图片说明

status 1 says that these two aren't equal.状态 1 表示这两个不相等。

Is there any way to make them equal or do i have to replace all these instances in the text with "有什么方法可以使它们相等,或者我是否必须将文本中的所有这些实例替换为

When comparing strings having characters that should be treated as equivalent they are typically "folded" together.当比较具有应被视为等效字符的字符串时,它们通常被“折叠”在一起。

On one hand there are projects like fold-to-ascii , which I have not used, that fold quite a few similar characters.一方面,有像fold-to-ascii这样的项目,我没有使用过,它折叠了很多相似的字符。

On the other hand you can create a simple remapping yourself, say something like this, which splits the string into an array of characters, remaps each character found in the equivalence mapping and joins the result back into a string.另一方面,您可以自己创建一个简单的重新映射,比如这样,它将字符串拆分为一个字符数组,重新映射在等价映射中找到的每个字符并将结果连接回一个字符串。

 var equivalenceMap = { '“': '"', '”': '"', ''': "'", ''': "'" }; function foldString(src) { return src.split('').map(function (c) { return (c in equivalenceMap) ? equivalenceMap[c] : c; }).join(''); } console.log('Strings equivalent: ' + (foldString('“collection') == foldString('"collection')));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM