那位大俠把下述C源碼轉(zhuǎn)為delphi,下述源碼為數(shù)字金額轉(zhuǎn)泰文,。
public static String ThaiBahtText(String strNumber, boolean IsTrillion) throws Exception{String BahtText = "";String strTrillion = "";String[] strThaiNumber = { "?????", "?????", "???", "???", "???", "???", "??", "????", "???", "????", "???" };String[] strThaiPos = { "", "???", "????", "???", "?????", "???", "????" };String strInteger = ***.split(".")[0];String strSatang = "00";if(***.split(".").length==1){strSatang = "00";}if(***.split(".").length>1){if(***.split(".")[1].length() < 2){strSatang=***.split(".")[1]+"0";}else{strSatang=***.split(".")[1];}} if (***.length() > 13) throw new Exception("???????????????????? ???????? ????????!"); boolean _IsTrillion = ***.length() > 7 ; if (_IsTrillion) { system.***.println(***.length()); strTrillion = ***.substring(0, ***.length() - 6); system.***.println(strTrillion); BahtText = ThaiBahtText(strTrillion, _IsTrillion); strInteger = ***.substring(***.length()); } int strLength = ***.length(); for (int i = 0; i < ***.length(); i++) { String number = ***.substring(i, (i+1)); if (!"0".equals(number)) { if (i == strLength - 1 && "1".equals(number) && strLength != 1) { BahtText += "????"; } else if (i == strLength - 2 && "2".equals(number) && strLength != 1) { BahtText += "???"; } else if (i != strLength - 2 || !"1".equals(number)) { BahtText += strThaiNumber[***.parseint(number)]; } BahtText += strThaiPos[(strLength - i) - 1]; } } if (IsTrillion){return BahtText + "????";} if(!"0".equals(strInteger)) { BahtText += "???"; } if ("00".equals(strSatang)) { BahtText += "????"; }else { strLength = ***.length(); for (int i = 0; i < ***.length(); i++) { String number = ***.substring(i, (i+1)); if (!"0".equals(number)) { if (i == strLength - 1 && "1".equals(number) && !"0".equals(***.substring(0,1))) { BahtText += "????"; } else if (i == strLength - 2 && "2".equals(number) &&!"0".equals(***.substring(0,1))) { BahtText += "???"; } else if (i != strLength - 2 || !"1".equals(number)) { BahtText += strThaiNumber[***.parseint(number)]; } BahtText += strThaiPos[(strLength - i) - 1]; } } BahtText += "??????"; }return BahtText;}
你的程序根本不是C的,,是java的,改為delphi沒有任何難度,,只是要化功夫
二小時(shí)搞定,,沒有泰文環(huán)境(也不想安裝它了),你自己測(cè)試下(注意字符集)
uses ***.strutils, ***.sysutils; { uses StrUtils,SysUtils; //低版本用}function ThaiBahtText(strNumber: String; IsTrillion: Boolean): String;conststrThaiNumber: Array [0 .. 10] of String = ('?????', '?????', '???', '???', '???', '???', '??','????', '???', '????', '???');strThaiPos: Array [0 .. 6] of String = ('', '???', '????', '???', '?????', '???', '????');varBahtText, strTrillion, strInteger, strSatang, number: String;_IsTrillion: Boolean;strLength, i: integer;beginBahtText := '';strTrillion := '';strInteger := SplitString(strNumber, '.')[0];strSatang := '00';if Length(SplitString(strNumber, '.')) = 1 thenbeginstrSatang := '00';end;if Length(SplitString(strNumber, '.')) > 1 thenbeginif Length(SplitString(strNumber, '.')) < 2 thenbeginstrSatang := SplitString(strNumber, '.')[1] + '0';endelsebeginstrSatang := SplitString(strNumber, '.')[1]end;end;if (Length(strInteger) > 13) thenraise ***.create ('???????????????????? ???????? ????????!') ;if Length(strInteger) > 7 then_IsTrillion := trueelse_IsTrillion := false;if _IsTrillion thenbeginwriteln(Length(strInteger));strTrillion := copy(strInteger, 1, Length(strInteger) - 5);writeln(strTrillion);BahtText := ThaiBahtText(strTrillion, _IsTrillion);strInteger := copy(strInteger, 1, Length(strTrillion));end;strLength := Length(strInteger);for i := 0 to Length(strInteger)-1dobegin number := copy(strInteger, i+1, 1);if not ('0' = number) thenbeginif (i = strLength - 1) and ('1'=number) and (strLength <> 1) thenbegin BahtText :=BahtText+ '????'; end else if (i = strLength - 2 ) and ('2'= number) and ( strLength <> 1) then begin BahtText := BahtText+'???';end else if (i <> strLength - 2) or not ('1' = number) then beginBahtText := BahtText+strThaiNumber[StrtoInt(number)];end;BahtText := BahtText+strThaiPos[(strLength - i) - 1];end;end;if IsTrillion thenbeginresult:= BahtText + '????';exitend;if not ('0'=strInteger) thenbeginBahtText :=BahtText + '???';end;if '00'=strSatang then beginBahtText := BahtText+'????';end else begin strLength := length(strSatang);for i := 0 to length(strSatang)-1 do begin number := copy(strSatang,i+1, 1);if not ('0'=number) then beginif (i = strLength - 1) and ('1'=number) and (not ('0'=copy(strSatang,1, 1))) then beginBahtText := BahtText+'????'; endelse if (i = strLength - 2) and ('2'=number) and (not ('0'=copy(strSatang,1, 1))) then beginBahtText := BahtText+'???';end else if (i <> strLength - 2) or (not ('1'=number)) then beginBahtText := BahtText+strThaiNumber[strtoint(number)];end;BahtText := BahtText+strThaiPos[(strLength - i) - 1];end;end;BahtText := BahtText+'??????';end;result:= BahtText;end;begin //測(cè)試writeln(ThaiBahtText('123.45', false));end.