2012-03-14 8 views
0

私はAlphabet.xmlファイルにあるunicharアラビア文字を通常のアラビア文字にエンコードしてください。たとえば、0x0628を通常のアラビア語のب(B)にエンコードします。私が使用している:普通の文字にアラビア文字をunicharでエンコード

-(void)loadDataFromXML{ 

    NSString* path = [[NSBundle mainBundle] pathForResource: @"alphabet" ofType: @"xml"]; 
    NSData* data = [NSData dataWithContentsOfFile: path]; 
    NSXMLParser* parser = [[NSXMLParser alloc] initWithData: data]; 
    [parser setDelegate:self]; 
    [parser parse]; 
    [parser release];  
    } 



    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict{ 

if ([elementName isEqualToString:@"letter"]) { 
     NSString* title = [attributeDict valueForKey:@"name"];  
     NSString * charcode =[attributeDict valueForKey:@"charcode"]; 
     NSLog(@"%@",[NSString stringWithFormat:@"%C",charcode]); 

     } 
    } 

NSLogが、それは私が前に見たことのない中国や何か何とか何とか何とかシンボルを出力します。しかし、私はちょうどそれを通常のアラビア語の文字に変換する下にコード化されたUnicodeを入れます。助けてください!!

NSLog(@"%@",[NSString stringWithFormat:@"%C", charcode]); 

同等です:::(

NSLog(@"%@",[NSString stringWithFormat:@"%C",0x0628]); 

答えて

1

問題は、あなたのコードがあることである。

NSLog(@"%@",[NSString stringWithFormat:@"%C", @"0x0628"]); 

しかしstringWithFormatが整数0x0628ではなく、文字列@"0x0628"を期待している


したがって、使用する前にcharcodeに変換する必要があります。次のコードを使用していることを達成することができます:

uint charValue; 
[[NSScanner scannerWithString:charcode] scanHexInt:&charValue]; 
NSLog(@"%@",[NSString stringWithFormat:@"%C", charValue]); 

最後に、あなたは、単に使用して、中間文字列を作成せずに文字をログに記録することができます注:

NSLog(@"%C", charValue); 
+0

それは働きました。どうもありがとうございました。神を祝福しなさい。 –

関連する問題