zoukankan      html  css  js  c++  java
  • 金额数字转中文大写(银行所需)

    - (NSString *)moneyStringWithDigitStr:(NSString *)digitString

    {

        NSLog(@"The begin string:%@",digitString);

        NSArray *datas = [NSArrayarrayWithObjects:@"", @"", @"", @"", @"", @"", @"", @"", @"", @"", nil];

        NSArray *infos = [NSArrayarrayWithObjects:@"", @"", @"", @"", @"", @"", @"", @"", @"亿", @"", @"", @"", @"", nil];

        

        NSMutableString *processString = [[NSMutableString alloc] initWithString:digitString];

        

        // creat a new mutable string

        NSMutableString *resultString = [NSMutableStringstring];

        int i = 0;

        int j = processString.length;

        

        // str:165047523

        // 1亿 6 5 0 4 7 5 2 3 ——> 壹亿 陆仟 伍佰 零拾 肆万 柒仟 伍佰 贰拾 叁分

        

        while (processString.length != 0) {

            

            // Add location tags after each number

            [resultString insertString:[infos objectAtIndex:i] atIndex:0];

            i++;

            

            // Obtain a character (a number), then the number corresponding uppercase characters restructuring to the ‘resultString’

            j--;

            NSString *specifiedNumberStrAtIndex = [processString substringWithRange:NSMakeRange(j, 1)];

            int specifiedNumber = [specifiedNumberStrAtIndex intValue];

            

            int number = specifiedNumber % 10;

            

            [resultString insertString:[datas objectAtIndex:number] atIndex:0];

            

            // Delete of a character, so that the next time through the loop with

            [processString deleteCharactersInRange:NSMakeRange(j, 1)];

            

            NSLog(@"resultString = %@",resultString);

        }

        

        NSString *moneyString = [NSString stringWithFormat:@"%@",resultString];

        

        // To use regular expressions to replace specific characters

        NSError *error=nil;

        NSArray *expressions = [NSArrayarrayWithObjects:@"[拾佰仟]", @"+亿", @"+", @"+", @"+",@"亿万",nil];

        NSArray *changes = [NSArray arrayWithObjects:@"", @"亿",@"",@"",@"",@"亿",nil];

        

        for (int k = 0; k < 6; k++)

        {

            NSRegularExpression *reg=[[NSRegularExpressionalloc] initWithPattern:[expressions objectAtIndex:k] options:NSRegularExpressionCaseInsensitiveerror:&error];

            

            moneyString = [reg stringByReplacingMatchesInString:moneyString options:0range:NSMakeRange(0, moneyString.length) withTemplate:[changes objectAtIndex:k]];

            

            NSLog(@"moneyString = %@",moneyString);

        }

        return moneyString;

    }

     

     

    祝您愉快开心 ^_^

  • 相关阅读:
    窗体控件随窗体大小改变(包括字体大小)
    Silverlight数据加载时,等待图标显示与隐藏(Loading)
    鼠标经过时,地图上的每个城市变颜色并且有提示框
    开始博客生活
    光纤
    静态路由配置(Static Routing)
    对称加密与非对称加密
    RIP Debug 过程
    WORD 固定表头自动生成/在Word表格接续页加上重复表格标题
    RIP路由
  • 原文地址:https://www.cnblogs.com/tianglin/p/3079852.html
Copyright © 2011-2022 走看看