为什么字符串在我的例子中不相等?
Why Strings are not equal in my case?
我有 currencyFormatter
与 se_SV
语言环境。
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
。
let firstString = currencyFormatter.string(from: NSNumber(value: 22222222.50)) // "22 222 222,50 "
然后我手动创建 String
与 firstString
相同。
let secondString = "22 222 222,50 "
为什么当我检查 firstString == secondString
是否收到 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
显示数字格式化程序用 "non-breaking spaces" U+00A0
分隔组。这样可以防止数字被拆分
多行文本中的行。
我有 currencyFormatter
与 se_SV
语言环境。
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
。
let firstString = currencyFormatter.string(from: NSNumber(value: 22222222.50)) // "22 222 222,50 "
然后我手动创建 String
与 firstString
相同。
let secondString = "22 222 222,50 "
为什么当我检查 firstString == secondString
是否收到 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
显示数字格式化程序用 "non-breaking spaces" U+00A0
分隔组。这样可以防止数字被拆分
多行文本中的行。