Swift - Replace Character in String

Bogdan Bogdanov picture Bogdan Bogdanov · Jul 2, 2014 · Viewed 14.2k times · Source

I have variable which contents the symbol or character I don't know how you say on this "\" in english... How to replace all \ with empty space in my variable ?

var content = theContent["content"] as String
self.contentLabel.text = content.stringByReplacingOccurrencesOfString(<#target: String#>, withString: <#String#>, options: <#NSStringCompareOptions#>, range: <#Range<String.Index>?#>)

How to fill this spaces or my sintax is wrong when I use content.string... and then in #target I use the same string ? Anyone who learned Swift so fast? :D

Answer

nicael picture nicael · Jul 2, 2014

Use the following

self.contentLabel.text = content.stringByReplacingOccurrencesOfString("\\", withString: " ", options: NSStringCompareOptions.LiteralSearch, range: nil)