Hi I want to convert the NSString into Byte array.
if I have string like \"Hello\" then it convert into byte like this {65,23,56,56,56}.
thanks
Use -[NSString UTF8String]
which returns const char*
. Read the reference.
A general tip: if you want to find if a class has a method which does something, look up the official reference! I mean, on the web, there's not only Stack Overflow, but the API provider's (i.e. Apple's or Microsoft's) official documentations!
NSData *bytes = [test dataUsingEncoding:NSUTF8StringEncoding];
From the docs:
"Gets a given range of characters as bytes in a specified encoding."
- (BOOL)getBytes:(void *)buffer maxLength:(NSUInteger)maxBufferCount usedLength:(NSUInteger *)usedBufferCount encoding:(NSStringEncoding)encoding options:(NSStringEncodingConversionOptions)options range:(NSRange)range remainingRange:(NSRangePointer)leftover