#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { NSString *tempStr; //将要分割的字符串 NSMutableString * mutableString=[[NSMutableString alloc]initWithString:@"hello,world!ni hao"]; //分割字符串的字符集 NSCharacterSet * characterSet =[NSCharacterSet characterSetWithCharactersInString:@",! "]; //利用数组将分割后的字符串保存起来 NSArray *array=[mutableString componentsSeparatedByCharactersInSet:characterSet]; //快速枚举法 for (tempStr in array) { NSLog(@"%@",tempStr); } //枚举器法 NSEnumerator * enumerator =[array objectEnumerator]; while (tempStr=[enumerator nextObject]) { NSLog(@"%@",tempStr); } } return 0; }
本文出自 “网络学习总结” 博客,请务必保留此出处http://8947509.blog.51cto.com/8937509/1556711
原文地址:http://8947509.blog.51cto.com/8937509/1556711