C#使用正则表达式将数字转换为大写中文

public string NumberToChinese(decimal number)
    {
        string res = string.Empty;
        string s = number.ToString("#L#E#D#C#K#E#D#C#J#E#D#C#I#E#D#C#H#E#D#C#G#E#D#C#F#E#D#C#.0B0A");
        string d = Regex.Replace(s, @"((?<=-|^)[^1-9]*)|((?'z'0)[0A-E]*((?=[1-9])|(?'-z'(?=[F-L\.]|$))))|((?'b'[F-L])(?'z'0)[0A-L]*((?=[1-9])|(?'-z'(?=[\  .]|$))))", "${b}${z}");
        res = Regex.Replace(d, ".", m => "负点空零壹贰叁肆伍陆柒捌玖空空空空空空空空空拾佰仟萬億兆京垓秭穰"[m.Value[0] - '-'].ToString());
        res = res.Replace("空", "");
        if (res.Length > 0)
        {
            if (res.IndexOf("点") == res.Length - 1)
            {
                res = res.Substring(0, res.Length - 1);
            }
            if (number < 0)
            {
                res = "负" + res;
            }
        }
        return res;
    }

猜你喜欢

转载自blog.csdn.net/loopwastemytime/article/details/78454638
今日推荐