我有一个缓冲区,即char
指针。这个内容类似于:
aaa
bbb
ccc
如何从aaa
指针获取char
第一行?
我首先尝试将其转换为NSString,但我可以在Objective-c中将其拆分为\n
吗?
类似的东西:
arrayString[0] = "aaa"
,arrayString[1] = "bbb"
,arrayString[2] = "ccc"
答案 0 :(得分:6)
char *buffer = "aaa \n bbb \n ccc \n";
NSString *str = [NSString stringWithCString:buffer encoding:NSUTF8StringEncoding];
NSArray *arr = [str componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
NSLog(@"arr: %@", arr);