I have a string, something like "www.vanityURL.myWebsitesURL.com" and I want to strip off the extension, wether it is ".com", ".net", ".ru", etc... so how can I strip everything AFTER the LAST period?
Asked
Active
Viewed 762 times
1 Answers
4
Try this way:-
NSString* sURL = @"www.vanityURL.myWebsitesURL.com";
NSRange lastDotRange = [sURL rangeOfString:@"." options:NSBackwardsSearch];
if (lastDotRange.location != NSNotFound) {
return [sURL substringToIndex:lastDotRange.location];
} else {
return sURL;
}

Siva Charan
- 17,940
- 9
- 60
- 95
-
Incredible! I didn't know you could search backwards! Thankyou :) – Albert Renshaw Nov 27 '12 at 05:34