遍歷字符串 在oc中遍歷字符串的至少可以使用以下兩種方法 (1) 通過查找的方式來(這方式適合所有格式的子符串,推薦使用) NSString *newStr =@"abdcdddccdd00大家好哦"; NSString *temp = nil; for(int i =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]); }