Iphone UTF8String产生文字磅符号¬£;语言
出于某种原因,当我试图在iPhone应用程序中将货币符号打印到pdf文档中时,我会打印出来,而不是打印出来。(当iPhone设置为英国设置时,使用英镑符号) 这是我的代码:Iphone UTF8String产生文字磅符号¬£;语言,iphone,objective-c,utf-8,Iphone,Objective C,Utf 8,出于某种原因,当我试图在iPhone应用程序中将货币符号打印到pdf文档中时,我会打印出来,而不是打印出来。(当iPhone设置为英国设置时,使用英镑符号) 这是我的代码: text = [NSString stringWithFormat:@"%@", [Helper convertDoubleToCurrencyString:[item.Total floatValue]]]; WriteOutText
text = [NSString stringWithFormat:@"%@", [Helper convertDoubleToCurrencyString:[item.Total floatValue]]];
WriteOutTextInPDF(pdfContext, [text UTF8String], priceX, currentY, 16);
+(NSString*) convertDoubleToCurrencyString:(double) d{
NSDecimalNumber *decimal = (NSDecimalNumber*)[NSDecimalNumber numberWithDouble:d];
NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
return [currencyFormatter stringFromNumber:decimal];
}
void WriteOutTextInPDF(CGContextRef pdfContext, const char *text, int x, int y, int fontSize){
CGContextSelectFont (pdfContext, "Helvetica", fontSize, kCGEncodingMacRoman);
CGContextSetTextDrawingMode (pdfContext, kCGTextFill);
CGContextSetRGBFillColor (pdfContext, 0, 0, 0, 1);
CGContextShowTextAtPoint (pdfContext, x, y, text, strlen(text));
}
你知道我是怎么得到这个符号而不是这个表示的吗
任何帮助都将不胜感激。在UTF-8文本中,字符%由两个字节表示
0xc2 0xa3
。但在中,这两个字节表示两个字符和
您可以使用
[text-cStringUsingEncoding:NSMacOSRomanStringEncoding]
而不是[text-UTF8String]
来使用编码转换字符串。或者您可以尝试使用UIGraphicsPushContext
和使用UIKit绘制字符串,UIKit可能支持UTF-8。谢谢。这就解释了。我注意到了这两个字节,但不知道如何写出它们的Mac Roman表示形式。