I'm trying to remove an escape sequence (\p) from selected strings (for reuse in other places in my code). I want to create a separate object that holds that cleaned up string. Like this
(pseudo code)
NSString *stringWithEscSequence = anEdgewoodSecretPlace.placeName;
NSString *stringWithoutEscSequence = [removeTheEscSequenceP stringWithEscSequence];
(where removeTheEscSequenceP is what I'm trying to figure out how to do)
....
I played with NSString formats and I found related questions at Position of a character NSString and how to replace one substring with another in Objective C? I can break out the substring that follows the escape sequence use ideas from the second posting. So I thought then I should try to locate the actual index of the escape sequence. But I can't figure out how to do that. Also I think there is probably a less messy, more straightforward way to do this, that I'm not thinking of.
I was playing around with the first posting ideas, though I knew that I was in a kind of primitive mode. But as soon as I attempt to replace "ABCD" with "\". I get an error 'Missing terminating """ = except if I put the ABCD string back in I'm not missing any quotes. I think it's because of the special nature ofo the \ character.
Even if I could figure out how to search for the "\" and then a "p" following that, I don't think that's really the best way to approach this
NSCharacterSet *charSet = [NSCharacterSet characterSetWithCharactersInString:@"ABCD"];
NSRange range2 = [testCleanString rangeOfCharacterFromSet:charSet];
if (range2.location == NSNotFound) {
NSLog (@"Didn't find esc sequence");
} else {
NSLog (@"range.location is %lu",(unsigned long)range2.location );
}