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.
如何从 NSString 中删除前缀“test”?我已经尝试过stringByReplacingOccurrencesOfString:,但这不是我想要的,因为它是我不想从字符串的其他出现中删除的前缀。
stringByReplacingOccurrencesOfString:
NSString *prefixToRemove = @"test"; NSString *newString = [originalString copy]; if ([originalString hasPrefix:prefixToRemove]) newString = [originalString substringFromIndex:[prefixToRemove length]];