문제

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?

도움이 되었습니까?

해결책

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;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top