替换<;br>;在swift中使用\n

替换<;br>;在swift中使用\n,swift,string,Swift,String,我从服务器获取一个字符串,它包含,我想用\n 首先,我使用这个方法: let description = user.description.replacingFirstOccurrence(of: "<br>", with: "\n") 我可以请任何人帮我吗? 谢谢尝试改用replacingOccurrences。请在下面查找代码 let description = "This is a test for testing line break <br> Hope t

我从服务器获取一个字符串,它包含

,我想用
\n

首先,我使用这个方法:

 let description  = user.description.replacingFirstOccurrence(of: "<br>", with: "\n")
我可以请任何人帮我吗?
谢谢

尝试改用replacingOccurrences。请在下面查找代码

let description = "This is a test for testing line break <br> Hope this works as expected."
let filteredDescription  = description.replacingOccurrences(of: "<br>", with: "\n") 
let description=“这是一个测试断线的测试
希望它能按预期工作。” let filteredDescription=description.replacingOccurrences(of:“
”,with:“\n”)
description方法应仅用于调试目的。请查找名为“replaceAllOccurences…”或类似名称的函数。但最好是向更有经验的人展示这一切,因为我真的担心你的代码会变得更糟。阅读你引用的答案的全新注释-我不是唯一一个认为它不可能工作的人。@gnasher729发布代码后,页面刷新,我看到了你的注释。我想我们是在同一时间发布的。
Cannot invoke 'reduce' with an argument list of type '(String, @escaping (String, String) -> String)'
let description = "This is a test for testing line break <br> Hope this works as expected."
let filteredDescription  = description.replacingOccurrences(of: "<br>", with: "\n")