Reputation: 501
I have a buffer, that is char
pointer. The content of this is something like:
aaa
bbb
ccc
How can I just get the aaa
first line from that char
pointer?
I try to convert it into NSString first, but can I split it by \n
in Objective-c?
Something like:
arrayString[0] = "aaa"
, arrayString[1] = "bbb"
, arrayString[2] = "ccc"
Upvotes: 2
Views: 1243
Reputation: 10045
char *buffer = "aaa \n bbb \n ccc \n";
NSString *str = [NSString stringWithCString:buffer encoding:NSUTF8StringEncoding];
NSArray *arr = [str componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
NSLog(@"arr: %@", arr);
Upvotes: 6