I have a NSString that is dynamic and changes constantly. I need to take that NSString and replace occurrences of every character in it with @”” except the string @”\n”
So if I have
NSString *string = @"This is my string at 10:00PM\n I hate this string\n";
so If I remove everything except \n by replacing everything with @”” and replace the \n occurrences with 1, my new string in the end will be 11 since there are two occurrences. The string could also have any character that exists, so it needs to remove everything except \n.
How could I do this?
If you want a more convenient, albeit slightly more memory-intensive solution: