Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个字符串,比如“www.vanityURL.myWebsitesURL.com”,我想去掉扩展名,不管它是“.com”、“.net”、“.ru”等等……那怎么能我在最后一个时期之后剥离所有东西?
试试这种方式: -
NSString* sURL = @"www.vanityURL.myWebsitesURL.com"; NSRange lastDotRange = [sURL rangeOfString:@"." options:NSBackwardsSearch]; if (lastDotRange.location != NSNotFound) { return [sURL substringToIndex:lastDotRange.location]; } else { return sURL; }