你的位置:首页 > 操作系统

[操作系统]【代码笔记】字符串的分割


一,代码。

复制代码
- (void)viewDidLoad{  [super viewDidLoad];  // Do any additional setup after loading the view.    self.title=@"字符串的分割";      //一般的字符串的解析  NSString *string = @"One,Two,Three,Four";  NSLog(@"string:%@",string);  NSArray *array = [string componentsSeparatedByString:@","];  NSLog(@"array:%@",array);      //两个json数组连在一起的解析  NSString *jsonStringOther=[NSString stringWithFormat:@"{\"name\":\"李华\", \"sex\":\"女\", \"age\":\"20\" }\n{\"name\":\"李华\", \"sex\":\"女\", \"age\":\"20\" }"];  NSLog(@"-----jsonStringOther---%@",jsonStringOther);  NSArray *jsonArray = [jsonStringOther componentsSeparatedByString:@"\n"];  NSLog(@"jsonArray:%@",jsonArray);  }
复制代码

 

二,输出。

复制代码
2015-10-22 11:13:21.872 字符串的分割[4057:112931] string:One,Two,Three,Four2015-10-22 11:13:21.873 字符串的分割[4057:112931] array:(  One,  Two,  Three,  Four)2015-10-22 11:13:21.873 字符串的分割[4057:112931] -----jsonStringOther---{"name":"李华", "sex":"女", "age":"20" }{"name":"李华", "sex":"女", "age":"20" }2015-10-22 11:13:21.873 字符串的分割[4057:112931] jsonArray:(  "{\"name\":\"\U674e\U534e\", \"sex\":\"\U5973\", \"age\":\"20\" }",  "{\"name\":\"\U674e\U534e\", \"sex\":\"\U5973\", \"age\":\"20\" }")
复制代码