Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UTF8String产生文字磅符号¬£;语言_Iphone_Objective C_Utf 8 - Fatal编程技术网

Iphone UTF8String产生文字磅符号¬£;语言

Iphone UTF8String产生文字磅符号¬£;语言,iphone,objective-c,utf-8,Iphone,Objective C,Utf 8,出于某种原因,当我试图在iPhone应用程序中将货币符号打印到pdf文档中时,我会打印出来,而不是打印出来。(当iPhone设置为英国设置时,使用英镑符号) 这是我的代码: text = [NSString stringWithFormat:@"%@", [Helper convertDoubleToCurrencyString:[item.Total floatValue]]]; WriteOutText

出于某种原因,当我试图在iPhone应用程序中将货币符号打印到pdf文档中时,我会打印出来,而不是打印出来。(当iPhone设置为英国设置时,使用英镑符号)

这是我的代码:

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表示形式。