Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove double quotes from NSString

How do I remove double quotes from an NSString. Example:

//theMutableString: "Hello World"

[theMutableString replaceOccurrencesOfString:@"\"" withString:@"" options:NSCaseInsensitiveSearch range:(NSRange){0,[theMutableString length]}]

It doesn't seem to work, maybe since I had to escape the " in the replaceOccurrencesOfString?

like image 981
christo16 Avatar asked Nov 28 '22 20:11

christo16


2 Answers

Use the NSMakeRange function instead of your cast. This'll work:

[mString replaceOccurrencesOfString:@"\"" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [mString length])];
like image 120
mipadi Avatar answered Dec 18 '22 18:12

mipadi


How about this ?

NSCharacterSet *quoteCharset = [NSCharacterSet characterSetWithCharactersInString:@"\""];
NSString *trimmedString = [toBeTrimmedString stringByTrimmingCharactersInSet:quoteCharset];
like image 26
Yasuhiro Takagi Avatar answered Dec 18 '22 18:12

Yasuhiro Takagi