Swift Replace Multiple Characters in String

后端 未结 4 517
日久生厌
日久生厌 2021-02-05 13:07

Below is the following line of code I use to replace an HTML break tag with a carriage return. However, I have other HTML symbols that I need to replace and when I call this lin

4条回答
  •  遥遥无期
    2021-02-05 13:51

    As @matt mentioned you are starting over with the same content string. The stringByReplacingOccurrencesOfString method doesn't actually change anything in the original content string. It returns to you a new string with the replacement changes while content remains unchanged.

    Something like this should work for you

    let result1 = content.stringByReplacingOccurrencesOfString("

    ", withString:"\r") let result2 = result1.stringByReplacingOccurrencesOfString("  ", withString:" ") textView.text = result2

提交回复
热议问题