我从uitextfield框中得到输入。我可以将quotes(“'”)替换为empty(“”“)。使用
textfield.text.replacingOccurrences(of: "'", with: "")
不起作用
textfield.text = "name's"
let trim = textfield.text?.replacingOccurrences(of: "'", with: "")
预期输出:
名称
实际输出:
姓名
答案 0 :(得分:0)
text.replacingOccurrences
可以与正则表达式一起使用,因此使用组['`´]可以在这里工作(我不知道有任何元字符)。正如@Rob在评论中提到的那样,可能值得进一步扩展模式,例如[‘’’ʻ´]或[’’‛'’’`❛❜]或使用“ \ p {Quotation_Mark}”
let trim = text.replacingOccurrences(of: "['`´]", with: "", options: .regularExpression)
它不能代替è或é
let text = "name's are Josè and André, strings are `abc` and ´def´"
let trim = text.replacingOccurrences(of: "['`´]", with: "", options: .regularExpression)
print(trim)
收益
名字是Josè和André,字符串是abc和def