如何获取文本并从链接中修剪文本?

时间:2019-05-09 06:07:04

标签: swift

假设我有

"<p>I need <a href='www.alink.com'> www.alink.com / x /y </a>, along with this. </p>"

我要获取文本:I need www.alink.com/x/y, along with this.

我尝试通过以下方式删除html:

someString?.replacingOccurrences(of: "<[^>]+>", with: "", options: .regularExpression, range: nil)

然后我得到:I need www.alink.com / x / y, along with this.

我需要没有空格的链接文本,该怎么办?

1 个答案:

答案 0 :(得分:2)

尝试仅用字符替换空格和下一个下一个字符。

ans="Hello i am goutham /t /n /m"
ans.replace(" /", "/")

给出:

'Hello i am goutham/t/n/m'