1 Nov 2005 01:19
Re: NSData - Swap bytes?
CFString has encoding constants to explicitly specify the bytes as little endian or big endian. These constants didn't make their way into NSString yet, but you can specify CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingUTF16LE) as the NSStringEncoding argument to initWithData:encoding:. This way you wouldn't be swapping the NSData contents, but telling NSString to do the swapping. Ali Begin forwarded message: > From: Paul <paul@...> > Date: October 31, 2005 15:53:07 PST > To: omni-osx-dev <macosx-dev@...> > Subject: NSData - Swap bytes? > > Hi everyone, > Please oh please can someone tell me how to swap bytes contained in > an NSData obj. > > I have read in bytes from a little endian file ... the string is > encoded as 48006f00 6d006500.... which is a UTF16 string . .single > ascii chars separated by 0's > > So I have read the data into an NSData object and now am wanting to > copy my bytes into an NSString object with initWithData: mystring > encoding:NSUnicodeStringEncoding but I need to swap the bytes in > the data obj before I can do so. > > Any suggestions/tips would be greatly appreciated.(Continue reading)
RSS Feed