求:数字日期转为中文日期(汉字日期)的最优算法?(100分)

  • 主题发起人 主题发起人 sanqou
  • 开始时间 开始时间
S

sanqou

Unregistered / Unconfirmed
GUEST, unregistred user!
如题。我是初学者,查阅了一下以前的帖子。我想分别转换,即:<br>2006--二OO六年;8月--八月...18---十八日<br>不知道,大家在实际中是如何做的?
 
年:<br>function tochina(num:integer) :pchar;<br>begin<br> &nbsp; case num of<br> &nbsp; &nbsp; &nbsp; &nbsp;0:<br>result:='0';<br> &nbsp; &nbsp; &nbsp; &nbsp;1:<br>result:='一';<br> &nbsp; &nbsp; &nbsp; &nbsp;2:<br>result:='二';<br> &nbsp; &nbsp; &nbsp; &nbsp;3:<br>result:='三';<br> &nbsp; &nbsp; &nbsp; &nbsp;4:<br>result:='四';<br> &nbsp; &nbsp; &nbsp; &nbsp;5:<br>result:='五';<br> &nbsp; &nbsp; &nbsp; &nbsp;6:<br>result:='六';<br> &nbsp; &nbsp; &nbsp; &nbsp;7:<br>result:='七';<br> &nbsp; &nbsp; &nbsp; &nbsp;8:<br>result:='八';<br> &nbsp; &nbsp; &nbsp; &nbsp;9:<br>result:='九';<br> &nbsp; end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var ss,s:string;<br> &nbsp; &nbsp;i,iValue:integer;<br>begin<br> &nbsp;iValue:=2006;s:='';<br> &nbsp;for i:=1 to length(inttostr(iValue)) do begin<br> &nbsp; &nbsp;ss:=inttostr(iValue);<br> &nbsp; &nbsp;s:=s+tochina(strtoint(ss));<br> &nbsp;end;<br> &nbsp;showmessage(s);<br>end;<br>月、日:<br>procedure TForm1.Button2Click(Sender: TObject);<br>var ss,s1,s2,s:string;<br> &nbsp; &nbsp;i,iValue:integer;<br>begin<br> &nbsp;iValue:=strtoint(Edit1.Text);s:='';<br> &nbsp;ss:=inttostr(iValue);<br> &nbsp;if iValue&gt;20 then begin<br> &nbsp; &nbsp;s1:=ss[1];s2:=ss[2];<br> &nbsp; &nbsp;s:=tochina(strtoint(s1))+'十'+tochina(strtoint(s2));<br> &nbsp;end else if iValue=20 then<br> &nbsp; &nbsp;s:='二十'<br> &nbsp;else if iValue&gt;10 then begin<br> &nbsp; &nbsp;s1:=ss[1];s2:=ss[2];<br> &nbsp; &nbsp;s:='十'+tochina(strtoint(s2))<br> &nbsp;end else if iValue=10 then<br> &nbsp; &nbsp;s:='十'<br> &nbsp;else begin<br> &nbsp; &nbsp;s:=tochina(strtoint(ss));<br> &nbsp;end;<br> &nbsp;showmessage(s);<br>end;<br>你把Button1Click和Button2Click改成函数就可以了
 
上楼说得很清楚了,来晚了[^]
 
函数tochina用数组来处理更简单点,其他OK
 
多人接受答案了。
 
后退
顶部