C # implementation [Arabic digital conversion into Chinese capital)

xiaoxiao2021-03-06  120

The following C # code enables the function of converting the Arab number into Chinese capital, and the Visual Studio.Net 2003 is basically passed (without strict testing, I hope that you will find errors, contact the author in contact Fanz2000@sohu.com, or directly in 9cbs Notify the last reply). The code's master function is ConvertSum, and its parameters are the number string of the String type. Call in ASP.NET follows: Label1.Text = ConvertSum ( "numeric string"); its code is as follows: // Author: fanz2000 //Email:fanz2000@sohu.com /// /// converted digital amount Lord Function (including decimal) /// /// numeric string ///

Convert a string or error message prompt string after Chinese uppercase

Public String Convertsum (String Str) {if (! ispositportEcimal (STR)) Return "is not positive!"; if (Double.Parse (STR)> 999999999999.99) Return "The number is too big, you can't convete it, please enter 10,000 The amount below billion "; char [] ch = new char [1]; ch [0] = '.'; // decimal point string [] splitstr = null; // Define the number of strings after the decimal point divided Splitstr = Str.Split (ch [0]); // According to the decimal point segmentation string IF (splitstr.length == 1) // only integer part Return ConvertData (STR) "round"; ELSE // has a fractional part {String RSTR; RSTR = ConvertData (splitstr [0]) "circle"; // conversion integer part RSTR = Convertxiaoshu (splitstr [1]); // Convert the fractional part RETURN RSTR;}} ///// Determine if it is positive Digital string // /// Decision string ///

If you are a number, return true, otherwise return false

Public Bool IspositveDecimal (String Str) {Decimal D; Try {D = Decimal.Parse (Str);} Catch (Exception) {Return False;} IF (D> 0) Return True; Else Return False;} /// / // Conversion Digital (Integer) / / / / / / 需要 整 整 数 字 字 ///

Convert the string after Chinese uppercase

Public String ConvertData (String Str) {String Tmpstr = ""; String Rstr = ""; INT STRLEN = Str.Length; if (Strlen <= 4) // The number length is less than four bits {RSTR = ConvertDigit (STR);} ELSE {IF (Strlen <= 8) // The number length is greater than four digits, less than eight bits {tmpstr = str.substring (strlen-4, 4); // first intercept the last four digit RSTR = ConvertDigit (tmpstr); / / Convert the last four digits tmpstr = str.substring (0, strlen-4); // Intercept the remaining number // Plus two converted numbers plus 10,000th phase connection RSTR = String.concat (ConvertDigit (Tmpstr) " Wan ", RSTR); rstr = rstr.replace (" 万 "," 10,000 "); rstr = rstr.replace (" zero zero "," zero ");} else if (Strlen <= 12) // number Length than eight bits, less than twelve digits {tmpstr = str.substring (strlen-4, 4); // intercepted the last four digit RSTR = ConvertDigit (tmpstr); // Convert the last four digits TMPSTR = Str.Substring (Strlen-8, 4); // intercepted four digits rstr = string.concat 10,000 ", RSTR); tmpstr = str.substring (0, strlen-8); rstr = string. Concat (ConvertDigit (TMPSTR) "100 million", RSTR = RSTR.Replace ("零", "100 million"); rstr = rstr.Replace ("零 万 万", "zero"); rstr = rstr. Replace ("zero zero", "zero"); rstr = rstr.replace ("zero zero", "zero");}} Strlen = RSTR. Length; if (Strlen> = 2) {switch (r.SUBSTRING (Strlen-2, 2)) {Case "零": RSTR = rstr.substring (0, strlen-2) ""; case "Zero": rstr = rstr.substring (0, strlen-2) ""; Break; Case "10,000": rstr = rstr.substring (0, strlen-2) "10,000"; brease; "Yi Zero": rstr = rstr.substring (0, strlen-2) "100 million"; Break;}} Return RSTR;} // /// Translation number (fractional)

// / / / 需要 小 小 数 数 字 部分 字 字 字 字 字 成 成 成 成 成 成 成 成 成

public string ConvertXiaoShu (string str) {int strlen = str.Length; string rstr; if (strlen == 1) {rstr = ConvertChinese (str) "angle"; return rstr;} else {string tmpstr = str.Substring ( 0, 1); RSTR = ConvertChinese (TmpStr) "Corner"; Tmpstr = Str.Substring (1, 1); RSTR = ConvertChinese (Tmpstr) "Division"; RSTR = RSTR.Replace ("Zero", " "); Rstr = rstr.replace (" zero angle "," "); return}} /// // convert digital ///// converted strings (within four digits) /////

Public String ConvertDigit (String Str) {Int Strlen = Str.Length; String Rstr = ""; Switch (Strlen) {Case 1: RSTR = ConvertCHINESE (STR); Break; Case 2: RSTR = Convert2Digit (STR); Break; Case 3: RStr = Convert3Digit (STR); Break; Case 4: RStr = Convert4Digit (STR); Break;}}}}} ("Picking", "Pick"); strlen = rstr.length; return = rstr;} // / / / convert four digit /// public string converT4Digit (string str) {string str1 = str.substring (0, 1); string str2 = str.substring (1, 1); string str3 = STR. Substring (2, 1); string str4 = str.substring (3, 1); string = converTCHINESE (STR1) ""; rstring = convertCHINESE (STR2) ""; r "; rTRING = ConvertChinese (STR3) "Pick"; RString = ConvertChinese (STR4); rstring = rstring.replace ("zero", "zero"); rstring = rstring.replace ("zero", "zero"); rstring = rtring .Replace ("Zero Pick", "Zero"); rstring = rstring.replace ("zero zero", "zero"); rstring = rstring.replace ("zero zero", "zero"); rstring = rtring.replace ("Zero zero", "zero"); return} /// // Translation three digits /// public str ING Convert3Digit (String Str) {string str1 = str.substring (0, 1); string str2 = str.substring (1, 1); string str3 = str.substring (2, 1); string rstring = ""; rstring = ConvertCHINESE ""; rtring = convertCHINESE (STR2) "Pick"; RString = ConvertCHINESE (STR3); rstring = rstring.replace; rstring = rstring.replace ( "Zero", "zero"); rstring =

RString.Replace ("zero zero", "zero"); rstring = rstring.replace ("zero zero", "zero"); return RString;} //// / conversion two digits // PUBLIC STRING CONVERT2DIGIT (string str) {string str1 = str.substring (0, 1); string str2 = str.substring (1, 1); string = ""; rstring = convertChinese (str1) ""; rtring = ConvertChinese Str2); rstring = rstring.replace ("Zero Pick", "Zero"); rstring = rstring.replace ("zero zero", "zero"); return RString;} ///// Put a digital conversion Cheng Zhong's uppercase digital /// public string converTchinese (String Str) {// "Zero Zibo Luzi Lu Wei" String CSTR = ""; Switch (Str) {CASE "0": cstr = "zero"; breaf; case "1": cstr = "壹"; Break; Case "2": cstr = ""; Break; Case "3": cstr = "叁"; BREAK Case "4": cstr = ""; Break; Case "5": cstr = "Wu"; Break; Case "6": cstr = "Lu"; Break; Case "7": cstr = "柒" Break; Case "8": cstr = "捌"; Break; Case "9": cstr = "玖"; Break;} Return (CSTR);} Fanz2000 [

original]

Author Blog: http://blog.9cbs.net/fanz2000/

转载请注明原文地址:https://www.9cbs.com/read-126652.html

New Post(0)