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.

newsitemtests

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

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -