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 以便我可以只用旧字符串的某个部分制作一个新字符串?
例如,我有字符串“9 月 12 日星期一”,如何只挑出“星期一”部分?
使用NSRange
NSRange
例子:
NSRange range; range.location = 0; range.length = 6; NSString *Secondstring = [Firststring substringWithRange:dayRange];
如果 'Firststring' 包含“Monday the 12th of September”,打印 'Secondstring' 将只给出 'Monday'