Sam Shaikh Sam Shaikh - 9 days ago 5
HTML Question

How to replace specific character in HTML String in Swift?

I have HTML, parse into String in Swift. HTML comes from server.I have

webkit-playsinline=""

inside String.

I need to replace this

"webkit-playsinline="webkit-playsinline"


I made two Strings, for replacement

let string1 = "webkit-playsinline=\"\""
let string2 = "webkit-playsinline=\"webkit-playsinline\""


But, I am unable to to do Replace as no such method exists.

In short, How can I alter HTML/String in Swift.

Thanks.

Answer
 let string1 = "webkit-playsinline=\"\""
 let string2 = "webkit-playsinline=\"webkit-playsinline\""

 yourHTML = (yourHTML as NSString).stringByReplacingOccurrencesOfString(string1, withString: string2)

Happy Coding!