Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove quotes from String on Swift?

Tags:

swift

swift2

I am trying to remove quotes from Swift String something like:

"Hello"

so that the Swift String is just:

Hello

like image 520
Ansal Antony Avatar asked May 23 '16 07:05

Ansal Antony


2 Answers

You can simply use

Swift 1

var str: String = "\"Hello\""

print(str) // "Hello"

print(str.stringByReplacingOccurrencesOfString("\"", withString: "")) // Hello

Update for Swift 3 & 4

print(str.replacingOccurrences(of: "\"", with: "")) // Hello
like image 166
N J Avatar answered Oct 19 '22 08:10

N J


"\"Hello\"".stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString: "\""))
like image 35
Losiowaty Avatar answered Oct 19 '22 06:10

Losiowaty