2012-03-14 6 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, 그것은 내가 한 번도 본 적이 중국어 또는 뭔가 ㅋ ㅋ ㅋ ㅋ ㅋ ㅋ 기호를 인쇄합니다. 하지만 난 그냥 아래에 정상적인 아랍어 문자로 변환 유니 코드 인코딩 된 ilk 코드를 넣어. 도와주세요!! 에

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

그것은했다. 고맙습니다. 신의 축복. –