将 char* 解析为 NSString 在 Objective-C 中的第一个新行处停止

Parsing char* to NSString stops at first new line in Objective-C

我正在尝试将从库返回的字符串转换为 NSString 以与单独的 Objective-C API 一起使用,但是每当我将 char* 解析为 NSString 它似乎停在第一行。

示例:

char *tst = "POST /servers HTTP/1.0\r\nContent-Type: test/json\r\nContent-Length:10\r\n\r\n1234567890";
NSLog(@"(TEST) : TST = %@", [NSString stringWithUTF8String:tst]);

输出:

<Notice>: (TEST) : TST = POST /servers HTTP/1.0

I'm not sure if this is it ACTUALLY not parsing past the first new line, or if NSLog simply isn't displaying the rest of the string past the first newline character. And that's what I'm trying to figure out.


编辑:


I've also tried replacing the \r\n instances with only \n with no change.

示例:

char *tst = "POST /servers HTTP/1.0\r\nContent-Type: test/json\r\nContent-Length:10\r\n\r\n1234567890";
NSString *tstStr = [NSString stringWithUTF8String:tst];
NSLog(@"(TEST) : TST = %@", [tstStr stringByReplacingOccurrencesOfString:@"\r\n" withString:@"\n"]);

输出:

<Notice>: (TEST) : TST = POST /servers HTTP/1.0

您的代码应该可以工作。我刚刚尝试了一下,在 Xcode.

中查看调试日志时,它对我有用

请注意,您实际上会在 NSLog 输出中得到两行新行,一行用于 \r,另一行用于 \n