I have the following NSString
:
productID = @"com.sortitapps.themes.pink.book";
At the end, "book" can be anything.... "music", "movies", "games", etc.
I need to find the third period after the word pink so I can replace that last "book" word with something else. How do I do this with NSRange? Basically I need this:
partialID = @"com.sortitapps.themes.pink.";
You can use
-[NSString componentsSeparatedByString:@"."]
to split into components, create a new array with your desired values, then use[NSArray componentsJoinedByString:@"."]
to join your modified array into a string again.You can try a backward search for the dot and use the result to get the desired range:
Well, although this isn't a generic solution for finding characters, in your particular case you can "cheat" and save code by doing this:
Essentially, I'm treating the name as a filename and removing the last (and only the last) extension using the NSString method for this purpose.