为什么字符串在我的情况下不相等? [英] Why Strings are not equal in my case?
本文介绍了为什么字符串在我的情况下不相等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有 currencyFormatter
与 se_SV
语言环境.
I have currencyFormatter
that is with se_SV
locale.
var currencyFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.currencySymbol = ""
formatter.locale = Locale(identifier: "se_SV")
formatter.minimumFractionDigits = 2
formatter.maximumFractionDigits = 2
formatter.numberStyle = .currencyAccounting
formatter.isLenient = true
return formatter
}()
我正在将 NSNumber
转换为 String
.
I am converting NSNumber
to String
.
let firstString = currencyFormatter.string(from: NSNumber(value: 22222222.50)) // "22 222 222,50 "
然后我手动创建与 firstString
相同的 String
.
And than I create String
manually that is same as firstString
.
let secondString = "22 222 222,50 "
为什么当我检查 firstString == secondString
时我收到 false
?
Why when I check if firstString == secondString
I receive false
?
推荐答案
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.
这篇关于为什么字符串在我的情况下不相等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文