在Objective-C中有没有一种简洁的方法来切分字符串?到目前为止,我有:
f = [f stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:@""];
这不像Python的好:
^{pr2}$如果不得不做一些类似f[1:4]
的事情,那就更粗糙了:
f = [f stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:@""];
f = [f stringByPaddingToLength:(4-1) withString:@"" startingAtIndex:0];
您可能正在寻找以下方法:
例如,
^{pr2}$f = f[1:]
变成:并且
f = f[1:4]
变成:只需小心索引和范围不超出边界,否则将抛出
NSRangeException
!在尝试
substringWithRange:
。例如或者
^{pr2}$相关问题 更多 >
编程相关推荐