ios - XCTAssertEqual on string allways fails -
i trying parse dictionary newsitem object. xtassert("teststring" == "teststring")
or xctassertequal("teststring", "teststring")
not fail. use swift 3 , xcode 8.0.
xctassert(s == t) //also fails
i parse newsitem.newspreamble so
let newspreamble: string ... self.newspreamble = dictionary["newspreamble"] as? string ?? ""
from debugger output
(lldb) po (s.data(using: .utf8)! nsdata) <e2808be2 808b7465 73745374 72696e67>
one can see string has 2 "invisible" characters, e2 80 8b
utf-8 sequence u+200b
"zero width space".
removing white space @ start (and end) 1 possible solution:
var s = "\u{200b}\u{200b}teststring" print(s) // teststring print(s.data(using: .utf8)! nsdata) // <e2808be2 808b7465 73745374 72696e67> print(s == "teststring") // false s = s.trimmingcharacters(in: .whitespaces) print(s == "teststring") // true
Comments
Post a Comment