Reputation: 693
I am trying to remove quotes from Swift String
something like:
"Hello"
so that the Swift String
is just:
Hello
Upvotes: 18
Views: 17526
Reputation: 27505
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
Upvotes: 29
Reputation: 3489
In Swift 3:
let myString = "\"Hello\""
print(myString) // "Hello"
let myNewString = myString.replacingOccurrences(of: "\"", with: "")
print(myNewString) // Hello
Upvotes: 4
Reputation:
you can use \ to remove Quotes from string
\" (double quote)
\' (single quote)
example:
NSString *s = @"your String";
NSCharacterSet *newStr = [NSCharacterSet characterSetWithCharactersInString:@"/""];
s = [[s componentsSeparatedByCharactersInSet: newStr] componentsJoinedByString: @""];
NSLog(@"%@", s);
Upvotes: 0
Reputation: 1067
//try like this
var strString = "\"Hello\""
strString = strString.stringByReplacingOccurrencesOfString("\"", withString: "")
Upvotes: 1
Reputation: 999
str.stringByReplacingOccurrencesOfString("\"", withString: "")
Upvotes: 2
Reputation: 8006
"\"Hello\"".stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString: "\""))
Upvotes: 14