NSString *testsubstringToorFromIndex = @"test1234";
NSString *fromIndexstring = [testsubstringToorFromIndex substringFromIndex:2];
NSString *toIndexstring = [testsubstringToorFromIndex substringToIndex:2];
NSLog(@"subtringfromindex is %@",fromIndexstring);
NSLog(@"subtringToindex is %@",toIndexstring);
输出结果
2014-11-29 06:23:59.634 sdktest[587:11024] subtringfromindex is st1234
2014-11-29 06:23:59.634 sdktest[587:11024] subtringToindex is te
- (NSString *)substringFromIndex:(NSUInteger)anIndex
Description
Returns a new string containing the characters of the receiver from the one at a given index to the end.
- (NSString *)substringToIndex:(NSUInteger)anIndex
Description
Returns a new string containing the characters of the receiver up to, but not including, the one at a given index.
返回一个字符串,这个字符串截取接受对象字符穿范围是从索引0到给定的索引index
本文介绍了在Objective-C中如何使用NSString的方法substringFromIndex和substringToIndex来截取字符串的具体用法。通过实例展示了从指定索引开始截取直至字符串结尾,以及从字符串开头截取至指定索引前的子串。
1万+

被折叠的 条评论
为什么被折叠?



