开发者

nsinputstream to string?

Is there anyway to view the 开发者_开发问答values in a nsinputstream such as converting it to a string?


I'll assume you mean the data that's returned from NSInputStream:

- (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)len;

Try this:

NSInteger bytesRead = [myInputStream read:&byteBuffer maxLength:4096];
NSString *stringFromData = [[NSString alloc] initWithBytes:byteBuffer length:bytesRead encoding:NSUTF8StringEncoding];


If you are reading the data from a stream that is pointing at a file or a URL, you could NSString methods:

+ stringWithContentsOfFile:encoding:error:
+ stringWithContentsOfURL:encoding:error:

See the NSString class reference for the documentation of these methods.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜