且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么字符串在我的情况下不相等?

更新时间:2023-01-04 22:13:32

print(Array(firstString!.unicodeScalars))
// ["2", "2", "\u{00A0}", "2", "2", "2", "\u{00A0}", "2", "2", "2", ",", "5", "0", "\u{00A0}"]

print(firstString!.replacingOccurrences(of: "\u{A0}", with: " ") == secondString)
// true

显示数字格式化程序使用不间断空格"U+00A0 分隔组.这可以防止数字被拆分多行文本中的行.

reveals that the number formatter separates the groups with "non-breaking spaces" U+00A0. This prevents the number from being split across lines in a multi-line text.