Reputation: 3999
I am trying to remove quotes from something like:
"Hello"
so that the string is just:
Hello
Upvotes: 6
Views: 6872
Reputation: 6599
I only wanted to remove the first quote and the last quote, not the quotes within the string so here's what I did:
challengeKey = @"\"I want to \"remove\" the quotes.\"";
challengeKey = [challengeKey substringFromIndex:1];
challengeKey = [challengeKey substringToIndex:[challengeKey length] - 1];
Hope this helps others looking for the same thing. NSLog and you'll get this output:
I want to "remove" the quotes.
Upvotes: 3
Reputation: 5388
Check out Apple's docs:
You probably want:
stringByReplacingOccurrencesOfString:withString:
Returns a new string in which all occurrences of a target string in the receiver are replaced by another given string.
- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement
So, something like this should work:
newString = [myString stringByReplacingOccurrencesOfString:@"\"" withString:@""];
Upvotes: 14