怎样求得汉字的区位码, (100分)

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

sarny

Unregistered / Unconfirmed
GUEST, unregistred user!
var<br>pchar1:array[0..16]of char;<br>str,str1,s,pass:string;<br>wdstr:widestring;<br>i,j,h:integer;<br>//sendby32:array[0..31]of byte; //读取的二进制代码<br>f1,f2:file of byte;<br>flag1,flag:integer; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//汉字的ASCII码<br>//weiyi:integer; &nbsp; &nbsp; &nbsp; &nbsp; //在汉字库中的偏移位<br>//qu,wei:integer; &nbsp; &nbsp; &nbsp; &nbsp;//按拼音的区,位码<br>//c:char;<br>temp:byte;<br>temp1:array[0..31]of byte;<br>begin<br>str1:=edit1.Text;<br>wdstr:=str1;<br>strplcopy(pchar1,str1,16);<br>pass:='HZK16';<br>assignfile(f1,pass);<br>reset(f1);<br>pass:='four.res';<br>assignfile(f2,pass);<br>rewrite(f2);<br>for i:=0 to 7 do<br>begin<br>s:=wdstr[i+1];<br>if length(s)&gt;1 then &nbsp; &nbsp;//判断要读取的字母是汉字或英文<br>Begin<br>flag:=ord(pchar1[2*i])-$a0; //把ascii全设为正数<br>flag1:=ord(pchar1[2*i+1])-$a0;<br>flag1:=(flag*100+flag1);<br>end ;<br><br>这样用ord函数求得的区位码经显示过不对产生的是另处一个汉字‘中’字变成了‘邴’字,<br>求那位老大能帮我!
 
你计算出RichEdit共显示了多少行不就行了!
 
不那么简单,因每行的字高是不一样的!
 
让RichEdit显示最后一行,然后查看ScrollBar的Position<br>
 
to TurboDog<br>&nbsp; &nbsp;richedit.scrollbar.position我这样写原代码会出错啊,<br>不知是什么原因!<br>不知兄台可否把这段原代码写给我看下咯?<br>先谢了
 
帮忙啊,<br>另外有分加的,<br>怎样求得一个字符的ansi码,<br>同时怎样求得一个文件以二进存的数据,取出指定的字节,
 
function IsHz(Source: string): Bool;<br>begin<br>&nbsp; result := ((Word(Source[1]) shl 8 + Word(Source[2])) &gt;= $B0A1) and<br>&nbsp; &nbsp; ((Word(Source[1]) shl 8 + &nbsp; Word(Source[2])) &lt;= $D7F9)<br>end;
 
function ByteType(const S: string; Index: Integer): TMbcsByteType;<br>&nbsp;bytetype &nbsp;它可以判断一个字符串中,某个 Char 是单个字母,还是双字节的前一位或<br>后一位。<br>mbSingleByte 单字母<br>mbLeadByte 双字节第一位<br>mbTrailByte 双字节第二位<br>你用这个函数就可以很简单的判断是汉字还是英文<br>
 
试试这个:<br>function Test(Str: string): Boolean;<br>var<br>&nbsp; i: Integer;<br>begin<br>&nbsp; Result := False;<br>&nbsp; &nbsp; if ord(Str) &gt; $7F then<br>&nbsp; &nbsp; &nbsp; Result := True;<br>end;<br>procedure TForm1.Button1Click(Sender: TObject);<br>var i:char;<br>&nbsp; &nbsp; j:integer;<br>&nbsp; &nbsp; s:string;<br>begin<br>&nbsp; i:='4';//这个为初始阶段<br>&nbsp; s:=edit1.text;<br>&nbsp; for j:=1 to length(s) do<br>&nbsp; begin<br>&nbsp; &nbsp; &nbsp;if test[j] then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (i='4')or(i='0')then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i:=0;//这个为中文<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;inc(j);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i:='2';//这个为中英文混合<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (i='4')or(i='1')then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i:=2;//这个为中英文混合<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;inc(j);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i:='1';//这个为英文<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; end;<br>&nbsp;if i='0' then<br>&nbsp; showmessage("这个为中文")<br>&nbsp;else if i='1' then<br>&nbsp; showmessage("这个为英文")<br>&nbsp;else<br>&nbsp; showmessage("这个为中英文混合")<br><br>end;<br>
 
码表127位前和127位后
 
sw:widestring;<br>s,c:string;<br>sw:=s;<br>for i:=1 to length(sw) do <br>begin<br>&nbsp;c:=sw;<br>if length(c)&gt;1 then 双字节//汉字<br>end<br>
 
能不能比较直接的得到一个汉字的ASCII,<br>我用上面几种方法,<br>如:<br>VAR <br>str,str1,str2:string;<br>wdstring:widestring;<br>i:integer;<br>flag:longstring;<br>begin <br>str1:=edit1,text;<br>wdstring:=str;<br>for i:=1 to length(wdstring)-1 do<br>begin<br>str2:=wdstring;<br>flag:=(word(str2[1]) shl 8+word(str[2]));//老是报这里WORD函数的参数引用不正确。不能编绎通过:<br><br>end;<br>end;<br>这一段函数注明处编绎通不过,请问大侠这种方法可行吗? <br>不行请给我正确的解答, 分不够。可多加
 
请看以前的帖子<br><br>我想编一个打字测试程序,一边打一边显示字数和速度,但不知如何实现(特别是中文或者中英混合的情况)。 <br>&nbsp;<br>g622 (2000-11-19 19:43:20) &nbsp;<br>因为是打字就可以不考虑鼠标了,在onchange事件里,依次判断每个个字节是否大于128,<br>如是,汉字加一,且忽略后面的1个字符;若小于则是ascii。<br>公共变量<br>charcount:integer;中英文字符总数<br>v:integer;速度<br>st:tdatetime;开始时间<br><br>onchange:<br>k:=0;<br>for i:=1 to length(memo1.text) do<br>begin<br>&nbsp;//控制符号就不算了吧 <br>&nbsp;if ms=控制符号,10,13,tab等 then<br>&nbsp; &nbsp; continue;<br>&nbsp;//是否是中文<br>&nbsp;if ord(ms)&gt;128 then <br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;//ms+ms[i+1]是一个汉字<br>&nbsp; &nbsp; &nbsp; &nbsp;k:=k+1;<br>&nbsp; &nbsp; &nbsp; &nbsp;continue;<br>&nbsp; &nbsp;end<br>&nbsp;else<br>&nbsp; &nbsp;k:=k+1; &nbsp;<br>end;<br>charcount:=k;<br>v:=k/(now()-st);<br>
 
为什么啊,我用ord()函数求得的asic码与用vb求得的不一样啊,
 
如果想得到一个打字的程序,太容易了。我送个给你,用delphi5写的。留下e-mail
 
你的错误在于: 你总想把两个字节的汉字拼在一起。<br>一个汉字由两个字节组成,要判断连续的两个字节是否汉字,<br>关键是看其第一个字节是否满足 &gt;=$a0 条件, 这个条件对GBK汉字都适用<br>而如果一个汉字是GB2312中定义的最常用的6763个汉字, <br>则第一个字节和第二个节字都必须满足&gt;=$a0 条件的条件<br><br><br><br>&nbsp; &nbsp;nToLen := length(Form1.combobox1.Text);<br>&nbsp; &nbsp;k :=1;<br>&nbsp; &nbsp;while k &lt;nToLen do &nbsp;begin<br>&nbsp; &nbsp; &nbsp; stemp:=copy(Form1.combobox1.Text,k,2);<br>&nbsp; &nbsp; &nbsp; if (ord(stemp[1])&lt;$a0) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Form1.label1.Caption :=sTemp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Form1.label2.Caption :='不是汉字,请输入汉字';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;exit;<br>&nbsp; &nbsp; &nbsp; end;<br><br>&nbsp;<br>&nbsp;这是我以前的程序, 肯定可行, 只是你要把源代码看懂<br>(*************************************)<br>procedure SearchQuwei();<br>var<br>&nbsp; &nbsp;sTemp, sTemp1, sTemp2 : string;<br>&nbsp; &nbsp;i , j ,nLen :integer;<br>begin<br>&nbsp; &nbsp;sTemp1 :=''; &nbsp; sTemp2 :='';<br>&nbsp; &nbsp;stemp:=copy(Form1.combobox1.Text,1,2);<br>&nbsp; &nbsp;Form1.Label1.Caption :=sTemp;<br><br>&nbsp; &nbsp;nLen :=length(sTemp);<br>&nbsp; &nbsp;if nLen &lt;2 then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; Form1.label2.Caption :='不是汉字,请输入汉字';<br>&nbsp; &nbsp; &nbsp; if sTemp ='' then &nbsp;Form1.label2.Caption :='请输入待查询的汉字';<br>&nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp;end;<br><br>&nbsp; &nbsp;sTemp1 :=copy(sTemp,1,1); &nbsp; sTemp2 :=copy(sTemp,2,1);<br>&nbsp; &nbsp;i :=ord(sTemp1[1]) - $a0; &nbsp; j :=ord(Stemp2[1]) - $a0;<br>&nbsp; &nbsp;str(i, sTemp1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;str(j, sTemp2);<br>&nbsp; &nbsp;if length(sTemp1) &lt;2 then sTemp1 :='0'+sTemp1;<br>&nbsp; &nbsp;if length(sTemp2) &lt;2 then sTemp2 :='0'+sTemp2;<br><br>&nbsp; &nbsp;if (i&gt;=0) and (j&gt;=0) then Form1.label2.Caption :=sTemp1+sTemp2 &nbsp;//输出区位码<br>&nbsp; &nbsp;else Form1.label2.Caption :='不是汉字,请输入汉字';<br><br>&nbsp; &nbsp;Form1.ComboBox1.Items.Add(sTemp);<br><br>end;<br><br>
 
to htw我开始也用这你种方法取得区位码,可是我用它去读字库(UCDOS的HZK16字库),<br>可是区位码就是相差200~400,输入一个中字出来却是另处一个字,苦了我一天!现在还不为何故<br>现在我用WORD函数来求的,也是分好节结果却是对的,谢谢!<br>to childbaby 我这个问题到是解决了,我这个程序是为单片机发送矩阵二进制信息用的,<br>不过我对你那个打字练习也很兴趣能让那个代码让我看看好吗?<br>MY EMAIL:sarny_12@163.net<br>
 
多人接受答案了。
 
后退
顶部