Assuming that there are no %
signs inside your strings of interest (e.g "a%ab%b%c"), you could use the componentsSeparatedByString:
or componentsSeparatedByCharactersInSet:
to get an array of strings separated by the %
sign. From there, it's pretty easy to figure out which strings in that array are between the percent signs, and which are unnecessary.
I think internally though, those methods are likely implemented as something like a loop looking for %
s. Maybe they parallelize the search on big strings, or use special knowledge of the internal structure of the string to make things faster -- those are the only ways I can see to speed up the search, assuming that you're stuck with keeping it all in a %
delimited string (if speed is really an issue, then the answer is probably to use an alternative representation).