views:

32

answers:

2

Hi all,

in my project i want to convert NSString value to NSdata without encoding, i.e i am using

NSData* aData = [[NSData alloc] initWithData:[[self getStringValue] dataUsingEncoding:NSUTF8StringEncoding]];

when i am using this the string value is encoded but i want the same string value without encoding, How can i get this

Thank You

A: 

You need an encoding otherwise it won't work. It needs to know what format the string is stored in. It needs to know what format the bytes are stored in. However you should probably be using the NSACSIIStringEncoding.

Justin Meiners
Hi Justin thanks for quick reply, Actually i have to covert the string to data and pass it to [[NSXMLParser alloc] initWithData:data] if i am converting the value is encoding and i am not able to get parsed values
kiri
A: 

You will always need to choose an encoding of some type. I always recommend NSUTF8StringEncoding. But if you only need the raw character bytes stored and not UTF8 encoding, these are your best options.

// for latin/english only characters
NSData* aData = [self dataUsingEncoding:NSACSIIStringEncoding];

// for international characters
NSData* aData = [self dataUsingEncoding:NSUnicodeStringEncoding]; 
jojaba