2014-05-22 3 views
3

오프라인 모드에서 모든 언어의 숫자를 영어 형식으로 변환하려합니다. 아랍어로 10.00을 "10.00"으로 설정하면 의미합니다. 다시 10.00으로 변환하고 싶습니다.특정 언어의 숫자를 특정 언어로 변환

일부 링크가 있지만이 경우에는 이렇게하는 것이 좋습니다. 왜냐하면 나는 모든 언어에 대해 작성해야하기 때문입니다. convert kABPersonPhoneProperty to arabic numbers

사람이 내가 이런 식으로 해결이

+0

이 http://stackoverflow.com/questions/11670330/how-to-display-arabic-numbers-inside-iphone-apps-without-localizing-each-digit 시도 ;) –

+0

안녕하세요 Nathan Hegedus, 답변 해 주셔서 감사합니다. 아랍어 숫자를 영어로 변환하는 경우 NAN을 다시 시도했습니다. @ "10"및 로캘을 @ "en_US"로 10 개 사용했습니다. –

답변

2

해결을 도와 주실 래요

BOOL isCommaUsingCountry = [자기 ifCountryCodePresentIntheList]

NSString *strAfterReplacing = @""; 
if (isCommaUsingCountry) 
{ 
    //If some numbers come like “10.000,00” 
    NSString *strAfterReplacingDot = [str stringByReplacingOccurrencesOfString:@"." withString:@""]; 
    strAfterReplacing = [strAfterReplacingDot stringByReplacingOccurrencesOfString:@"," withString:@"."]; 

    //For removing Arabic comma 
    strAfterReplacing = [strAfterReplacing stringByReplacingOccurrencesOfString:@"٫" withString:@"."]; 

} 
else 
{ 
    strAfterReplacing = [str stringByReplacingOccurrencesOfString:@"," withString:@""]; 
} 

NSArray *separray = [strAfterReplacing componentsSeparatedByString:@"."]; 
NSString *numbersBeforeDecimal = @""; 
NSString *numbersAfterDecimal = @""; 
if([separray count] == 2) 
{ 
    numbersBeforeDecimal = [separray objectAtIndex:0]; 
    numbersAfterDecimal = [separray objectAtIndex:1]; 
} 

//Converting back to US format 
if([strAfterReplacing length] > 0) 
{ 
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; 
    NSLocale *usLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]; 
    [formatter setLocale:usLocale]; 
    NSNumber *newNum1 = [formatter numberFromString:numbersBeforeDecimal]; 
    NSNumber *newNum2 = [formatter numberFromString:numbersAfterDecimal]; 
    numbersBeforeDecimal = [NSString stringWithFormat:@"%@", newNum1]; 
    numbersAfterDecimal = [NSString stringWithFormat:@"%@", newNum2]; 
} 
NSString *combinedStr = [NSString stringWithFormat:@"%@.%@", numbersBeforeDecimal, numbersAfterDecimal];