"iOS Development series" converts Arabic numerals to Chinese numerals

Source: Internet
Author: User

/** * Convert Arabic numerals to Chinese numerals */+ (NSString *) Translationarabicnum: (nsinteger) arabicnum{nsstring *arabicnumstr = [NSString Strin    gwithformat:@ "%ld", (long) arabicnum];    Nsarray *arabicnumeralsarray = @[@ "1", @ "2", @ "3", @ "4", @ "5", @ "6", @ "7", @ "8", @ "9", @ "0"];    Nsarray *chinesenumeralsarray = @[@ "One", @ "two", @ "three", @ "four", @ "five", @ "six", @ "seven", @ "eight", @ "nine" @ "0"];    Nsarray *digits = @[@ "A", @ "ten", @ "hundred", @ "thousand", @ "Million", @ "ten", @ "hundred", @ "thousand", @ "Million", @ "ten", @ "hundred", @ "thousand", @ "Mega"];        Nsdictionary *dictionary = [nsdictionary dictionarywithobjects:chinesenumeralsarray ForKeys:arabicNumeralsArray];        if (Arabicnum < && arabicnum > 9) {if (Arabicnum = =) {return @ "ten";            }else{nsstring *substr1 = [Arabicnumstr substringwithrange:nsmakerange (1, 1)];            NSString *a1 = [dictionary objectforkey:substr1];            NSString *chinese1 = [NSString stringwithformat:@ "10%@", A1];        return chinese1;        }}else{Nsmutablearray *sums = [Nsmutablearray array]; for (int i = 0; i < arabicnumstr.length;            i + +) {nsstring *substr = [Arabicnumstr substringwithrange:nsmakerange (I, 1)];            NSString *a = [dictionary objectforkey:substr];            NSString *b = digits[arabicnumstr.length-i-1];            NSString *sum = [a stringbyappendingstring:b]; if ([a isequaltostring:chinesenumeralsarray[9]]) {if ([b isequaltostring:digits[4]] | |                [b isequaltostring:digits[8]])                    {sum = b; if ([[[Sums Lastobject] isequaltostring:chinesenumeralsarray[9]) {[Sums removel                    Astobject];                }}else {sum = chinesenumeralsarray[9]; } if ([[[Sums Lastobject] isequaltostring:sum]) {continue                ;        }} [sums addobject:sum];   }     NSString *sumstr = [sums componentsjoinedbystring:@ ""];        NSString *chinese = [Sumstr substringtoindex:sumstr.length-1];    return Chinese; }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"iOS Development series" converts Arabic numerals to Chinese numerals

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.