遍历字符串
2017-01-15 本文已影响24人
coderK
(1) 通过查找的方式来(这方式适合所有格式的子符串,推荐使用)
NSString*newStr =@"abdcdddccdd00大家好哦";
NSString*temp =nil;
for(inti =0; i < [newStr length]; i++)
{
temp = [newStr substringWithRange:NSMakeRange(i,1)];
NSLog(@"第%d个字是:%@",i,temp);
}
(2) 通过遍历字符的方式遍历字符串(只适合不包含中文的字符串)
NSString*newStr =@"abdcdddccdd00";
for(int i =0; i < [newStr length]; i++)
{
NSLog(@"第%d个字符是:%@",i, [newStr characterAtIndex:i]);
}