Nsinputstream for string?

Is there anyway viewing the values ​​in the nsinput stream, for example converting it to a string?

+3
source share
2 answers

I assume you mean the data returned from NSInputStream:

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

Try the following:

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

If you are reading data from a stream pointing to a file or URL, you can use the NSString methods:

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

Refer to the NSString class reference for documentation of these methods.

0
source

All Articles