Remove HTML Tags from an NSString on the iPhone

前端 未结 22 1607
心在旅途
心在旅途 2020-11-22 10:02

There are a couple of different ways to remove HTML tags from an NSString in Cocoa.

One way is to render the string into an

22条回答
  •  礼貌的吻别
    2020-11-22 10:31

    Here's the swift version :

    func stripHTMLFromString(string: String) -> String {
      var copy = string
      while let range = copy.rangeOfString("<[^>]+>", options: .RegularExpressionSearch) {
        copy = copy.stringByReplacingCharactersInRange(range, withString: "")
      }
      copy = copy.stringByReplacingOccurrencesOfString(" ", withString: " ")
      copy = copy.stringByReplacingOccurrencesOfString("&", withString: "&")
      return copy
    }
    

提交回复
热议问题