2011-10-28 141 views
1

正在將應用程序從java轉換爲objective-c,並且遇到了圍繞字符編碼的問題。字符編碼CP037

在Java代碼中的語句我試圖轉換爲:

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

我希望做到在Objective-C以下:

const char *instructions = [input CP037]; 

但是 「CP037」 不存在作爲編碼,有誰知道如何克服?

回答

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);