【问题标题】:Remove occurrence of Unicode character \u{ef} from String In Swift 3从 Swift 3 中的字符串中删除出现的 Unicode 字符 \u{ef}
【发布时间】:2017-11-25 22:08:54
【问题描述】:

在 Swift 3 中从 String 中删除出现的 Unicode 字符 \u{ef}

示例字符串:- "\u{ef}\n \n\u{ef}\n ????\n\u{ef}"

提前致谢。

【问题讨论】:

    标签: swift string unicode


    【解决方案1】:

    在您的String 上使用replacingOccurrences

    let str = "\u{ef}\n \n\u{ef}\n ?\n\u{ef}".trimmingCharacters(in: .whitespaces)
    let newStr = str.replacingOccurrences(of: "\u{ef}", with: "", options: NSString.CompareOptions.literal, range:nil)
    print(newStr) // ?
    

    【讨论】:

    • 我也试过这个函数用于字符串替换发生函数但没有得到结果......例如: - var trimmedStr = UIUtils.removingWhiteSpace(self.composeBar.textView.text as NSString) as String trimmedStr = resultString.replacingOccurrences(of: "\u{ef}", with: "", options: NSString.CompareOptions.literal, range:nil) if trimmedStr > 0 { ChatPersistentService.persistChatDate(self.threadInfo.threadId.stringValue(), txt: trimmedStr,isPersistingChat: true) }
    • @BalKrishanYadav,您遇到的错误是removingWhiteSpace。我也更新了我的示例,删除了空格。
    • @Rashwan L 对我有任何帮助:stackoverflow.com/questions/45586825/…
    • @BalKrishanYadav,您找到解决方案了吗?如果我的回答有用,请单击它左侧的upvote 按钮。如果它回答了您的问题,请单击复选标记以接受它。这样其他人就知道你得到了(足够的)帮助。
    • @NikolaLukic,我去看看!
    猜你喜欢
    • 2017-02-20
    • 1970-01-01
    • 2019-05-30
    • 1970-01-01
    • 2017-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-26
    相关资源
    最近更新 更多