【代码笔记】iOS-字符串的分割

时间:2021-08-08 07:15:13

一,代码。

【代码笔记】iOS-字符串的分割
- (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); }
【代码笔记】iOS-字符串的分割

二,输出。

【代码笔记】iOS-字符串的分割
2015-10-22 11:13:21.872 字符串的分割[4057:112931] string:One,Two,Three,Four
2015-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\" }"
)
【代码笔记】iOS-字符串的分割