假设我有一个字符串
var a = "#bb #cccc #ddddd\u{ef}"
我将其设置为这样的 TextView
let text = a.trimmingCharacters(in: .whitespacesAndNewlines)
let textRemoved = text?.replacingOccurrences(of: "\u{ef}", with: "", options: NSString.CompareOptions.literal, range:nil)
textView.text = textRemove
我正在尝试删除此处的 \u{ef}
字符。但在 textRemoved
中却没有发生。请帮助我该怎么做。
I am using Xcode 10. Looks like below Xcode version than 10 is working fine. is it a bug of Xcode 10?
最佳答案
这是一个迟到的答案,但我也很难替换字符串中的“\u{ef}”。在调试过程中,当鼠标悬停在字符串上时,它显示\u{ef} 的存在,但在描述中打印时,它只显示空格。
let str = "\u{ef} Some Title"
print(str) //" Some Title"
我尝试了 replacingOccurrences(of: "\u{ef}", with: "", options: NSString.CompareOptions.literal, range: nil).trimmingCharacters(in: .whitespaces)
但是它也失败了。
所以我使用了下面的代码片段,它的效果就像奇迹一样。
let modifiedStr = str.replacingOccurrences(of: "\u{fffc}", with: "", options: NSString.CompareOptions.literal, range: nil).trimmingCharacters(in: .whitespaces)
print(modifiedStr) //"Some Title"
希望这对某人有帮助!!
关于ios - 如何从字符串Swift中删除 '\u{ef}'字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52886308/