字符编码CP037

时间:2011-10-28 14:15:32

标签: objective-c ios character-encoding

将应用程序从java转换为objective-c并遇到围绕字符编码的问题。

在java代码中,我试图转换的语句是:

byte[] instructions = input.getBytes("CP037");

我希望在objective-c中执行以下操作:

 const char *instructions = [input CP037];

然而“CP037”不作为编码存在,有谁知道如何克服?

1 个答案:

答案 0 :(得分:1)

到最后:

 NSString *stringThatNeedsToBeEncoded = @"randomString";  
 CFDataRef encodedStringAsCFData = CFStringCreateExternalRepresentation(CFAllocatorGetDefault(), (CFStringRef)stringThatNeedsToBeEncoded, kCFStringEncodingEBCDIC_CP037, 0); 

 CFIndex bufferLength = CFDataGetLength(encodedStringAsCFData);  
 UInt8 *buffer = malloc(bufferLength);  
 CFDataGetBytes(encodedStringAsCFData, CFRangeMake(0, CFDataGetLength(encodedStringAsCFData)), buffer);