Although iOS provides a lot of useful string methods, I can’t find a good solution for getting ranges of strings that are separated by a given character.
original string:
|You| will |achieve| everything you |want| if you |work| hard
separateness character is |.
separate string1: You (range: 3, 3)
separate string2: achieve (range: 12, 7)
separate string3: want (range: 37, 4)
separate string4: work (range: 51, 4)
NSString method’s substringFromIndex: makes it possible to find these ranges using NSString, but this seems inefficient.
Please, let me know the better ways to solve this.
You should use NSRegularExpression‘s matchesInString:options:range: method.
You might have code like:
Logs: