hz008:如何能将汉字转变成相应的十位数字(200分)

  • 主题发起人 主题发起人 hz008
  • 开始时间 开始时间
请说清楚些。什么是十位数字?
 
什么叫汉字相应的十位数字?
 
不明白!
 
十进制数?
 
取汉字内码不就行了?
 
是不是像这样, 1024 = 壹千零贰十肆 或反过来.<br>自己写一个对应表不就行了.没有难度,只是写起来麻烦一些,<br>大富翁上讨论过此问题.
 
如果是汉字GB码处理二个字节机内码<br>如果是汉字U8码处理四个字节机内码<br>
 
是不是将汉字转变为 二进制码?
 
一个简单的程序,只能转换最多999的数字(对于我要用到的已经足够了)<br><br>Function ConvertNumberToChinese(const c:string):string;<br>var<br>&nbsp; s:string;<br>&nbsp; i,theLength:integer;<br>Begin<br>&nbsp; s := '';<br>&nbsp; i := 1;<br>&nbsp; theLength := Length(c);<br><br>&nbsp; if(theLength - 2 = i) then<br>&nbsp; Begin<br>&nbsp; &nbsp; case c of<br>&nbsp; &nbsp; '1': s := s + '一百';<br>&nbsp; &nbsp; '2': s := s + '二百';<br>&nbsp; &nbsp; '3': s := s + '三百';<br>&nbsp; &nbsp; '4': s := s + '四百';<br>&nbsp; &nbsp; '5': s := s + '五百';<br>&nbsp; &nbsp; '6': s := s + '六百';<br>&nbsp; &nbsp; '7': s := s + '七百';<br>&nbsp; &nbsp; '8': s := s + '八百';<br>&nbsp; &nbsp; '9': s := s + '九百';<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; Inc(i);<br>&nbsp; end;<br><br>&nbsp; if(theLength - 1 = i) then<br>&nbsp; Begin<br>&nbsp; &nbsp; case c of<br>&nbsp; &nbsp; '0':<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if('0' = c[i+1]) then <br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := s;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; if('0' &lt;&gt; c[1]) then s := s + '零';<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; '1': s := s + '十';<br>&nbsp; &nbsp; '2': s := s + '二十';<br>&nbsp; &nbsp; '3': s := s + '三十';<br>&nbsp; &nbsp; '4': s := s + '四十';<br>&nbsp; &nbsp; '5': s := s + '五十';<br>&nbsp; &nbsp; '6': s := s + '六十';<br>&nbsp; &nbsp; '7': s := s + '七十';<br>&nbsp; &nbsp; '8': s := s + '八十';<br>&nbsp; &nbsp; '9': s := s + '九十';<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; Inc(i);<br>&nbsp; end;<br><br>&nbsp; if(theLength = i) then<br>&nbsp; Begin<br>&nbsp; &nbsp; case c of<br>&nbsp; &nbsp; '1': s := s + '一';<br>&nbsp; &nbsp; '2': s := s + '二';<br>&nbsp; &nbsp; '3': s := s + '三';<br>&nbsp; &nbsp; '4': s := s + '四';<br>&nbsp; &nbsp; '5': s := s + '五';<br>&nbsp; &nbsp; '6': s := s + '六';<br>&nbsp; &nbsp; '7': s := s + '七';<br>&nbsp; &nbsp; '8': s := s + '八';<br>&nbsp; &nbsp; '9': s := s + '九';<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br><br>&nbsp; Result := s;<br>end;<br>
 
对不起,是怎样转为十进制的数
 
是纯中文数字?只为100以下的做过:(里面如果有万、千、百,就不灵了)<br><br>function ConvertChineseToNumber(const s:string):integer;<br>var<br>&nbsp; i,theLength:integer;<br>&nbsp; num,PartOfS:string;<br>Begin<br>&nbsp; theLength := Length(s);<br>&nbsp; num := '';<br><br>&nbsp; if(thelength = 1) then num := '0';<br><br>&nbsp; i := 1;<br>&nbsp; if(s = '十') then<br>&nbsp; begin<br>&nbsp; &nbsp; Result := 10;<br>&nbsp; &nbsp; exit;<br>&nbsp; end;<br><br>&nbsp; PartOfS := Copy(s,i,2);<br>&nbsp; if(PartOfS = '十') then<br>&nbsp; Begin<br>&nbsp; &nbsp; num := num + '1';<br>&nbsp; &nbsp; Inc(i,2);<br>&nbsp; end;<br><br>&nbsp; while(i &lt; theLength) do<br>&nbsp; Begin<br>&nbsp; &nbsp; PartOfS := Copy(s,i,2);<br>&nbsp; &nbsp; if((PartOfS = '零') or (PartOfS = '0') or (PartOfS = '○')) then<br>&nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; num := num + '0';<br>&nbsp; &nbsp; &nbsp; Inc(i,2);<br>&nbsp; &nbsp; &nbsp; continue;<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else if(PartOfS = '十') then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Inc(i,2);<br>&nbsp; &nbsp; &nbsp; &nbsp; if(i = thelength - 1) then num := num + '0';<br>&nbsp; &nbsp; &nbsp; &nbsp; continue;<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; else if((PartOfS = '一') or (PartOfS = '1')) then<br>&nbsp; &nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; num := num + '1';<br>&nbsp; &nbsp; &nbsp; &nbsp; Inc(i,2);<br>&nbsp; &nbsp; &nbsp; &nbsp; continue;<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; else if((PartOfS = '二') or (PartOfS = '2') or (PartOfS = '廿')) then<br>&nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; num := num + '2';<br>&nbsp; &nbsp; &nbsp; &nbsp; Inc(i,2);<br>&nbsp; &nbsp; &nbsp; &nbsp; continue;<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; else if((PartOfS = '三') or (PartOfS = '3') or (PartOfS = '叁') or (PartOfS = '卅')) then<br>&nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; num := num + '3';<br>&nbsp; &nbsp; &nbsp; &nbsp; Inc(i,2);<br>&nbsp; &nbsp; &nbsp; &nbsp; continue;<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; else if((PartOfS = '四') or (PartOfS = '4')) then<br>&nbsp; &nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; num := num + '4';<br>&nbsp; &nbsp; &nbsp; &nbsp; Inc(i,2);<br>&nbsp; &nbsp; &nbsp; &nbsp; continue;<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; else if((PartOfS = '五') or (PartOfS = '5')) then<br>&nbsp; &nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; num := num + '5';<br>&nbsp; &nbsp; &nbsp; &nbsp; Inc(i,2);<br>&nbsp; &nbsp; &nbsp; &nbsp; continue;<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; else if((PartOfS = '六') or (PartOfS = '6')) then<br>&nbsp; &nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; num := num + '6';<br>&nbsp; &nbsp; &nbsp; &nbsp; Inc(i,2);<br>&nbsp; &nbsp; &nbsp; &nbsp; continue;<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; else if((PartOfS = '七') or (PartOfS = '7')) then<br>&nbsp; &nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; num := num + '7';<br>&nbsp; &nbsp; &nbsp; &nbsp; Inc(i,2);<br>&nbsp; &nbsp; &nbsp; &nbsp; continue;<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; else if((PartOfS = '八') or (PartOfS = '8')) then<br>&nbsp; &nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; num := num + '8';<br>&nbsp; &nbsp; &nbsp; &nbsp; Inc(i,2);<br>&nbsp; &nbsp; &nbsp; &nbsp; continue;<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; else if((PartOfS = '九') or (PartOfS = '9')) then<br>&nbsp; &nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; num := num + '9';<br>&nbsp; &nbsp; &nbsp; &nbsp; Inc(i,2);<br>&nbsp; &nbsp; &nbsp; &nbsp; continue;<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Inc(i);<br>&nbsp; &nbsp; &nbsp; &nbsp; continue;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; end;<br><br>&nbsp; if Length(num) = 0 then Result := 0<br>&nbsp; else &nbsp;Result := StrToInt(num);<br>end;<br><br>
 
也就是怎样取得汉字的内码,然后再转成十进制数字,帮帮忙!
 
以后问问题写清楚点,省得我费了老大劲,最后落个文不对题的下场。
 
批评的有道理,我因为进入这里很难,也容易掉线,所以敲问题时太匆忙<br>给大家道歉!
 
Very easy.<br><br>var str:string;<br>&nbsp; i:integer;<br>begin<br>&nbsp; str:='这是一个试验!';<br>&nbsp; Caption:=Format('length:%d',[Length(str)]);<br>&nbsp; for i:=1 to Length(str) do<br>&nbsp; &nbsp; Caption:=Caption+Format(',%d',[ord(str)]);<br>&nbsp; showmessage(chr(213)+chr(226)+chr(163)+chr(161));<br>end;<br>
 
不知你要做什么????<br>一般是读字库时需要此功能 供参考<br>var str:string;<br>&nbsp; &nbsp; code,hi,lo,i:ineger;<br>beging<br>&nbsp; str:='中’; //GB码为例<br>&nbsp; if (str[1]&gt;= 127) and (str[2]&gt;= 127) then //二个字节高位是否1<br>&nbsp; beging<br>&nbsp; &nbsp; hi:=str[1] and 127;//取区号<br>&nbsp; &nbsp; lo:=str[2] and 127;//取位号<br>&nbsp; &nbsp; code:=(hi-16)*94 + (lo - 1);//十进制数GB码位置<br>&nbsp; &nbsp; //以下字库结构不同算法而不同<br>&nbsp; end;<br>end;<br>&nbsp; &nbsp;
 
谢谢各位的帮助!
 
后退
顶部