The front end solves the problem that when comparing strings, the displayed content is the same but false is returned

Compares text containing line breaks at both ends.

console.llog displays the same content, for example:
string_a:

你最近不说话
怎么了 为什么
是不是有什么事让你不快乐

string_b:

你最近不说话
怎么了 为什么
是不是有什么事让你不快乐

However, comparing the lengths, we found they were inconsistent.

string_a.length != string_b.length

When JSON.stringify(string_a) is
used to display line breaks and other stuff,
it is found that the two are different, one is \n and the other is \r\n, so comparing strings will fail.

Solved by string_a.replace(/\r/g,'') replacement

Guess you like

Origin blog.csdn.net/weixin_44325637/article/details/89245494