?? 065.htm
字號:
<HTML><HEAD><meta http-equiv="Content-Type" content="text/html; charset=GB2312"><TITLE>-->DELPHI專題文檔-程序應用-->統計中英文字個數</TITLE>
<META NAME="keywords" CONTENT=" DELPHI專題文檔-程序應用 統計中英文字個數">
<META NAME="description" CONTENT=" - DELPHI專題文檔-程序應用 - 統計中英文字個數">
<style>
<!--
#page {position:absolute; z-index:0; left:0px; top:0px}
.tt3 {font: 9pt/12pt "宋體"}
.tt2 {font: 12pt/15pt "宋體"}
a {text-decoration:none}
a:hover {color: blue;text-decoration:underline}
-->
</style>
</HEAD>
<a href="index6.html">返回</a>
<body text="#000000" aLink=#9900ff link=#006699 vLink=#006699 bgcolor="#FFFFFF" leftmargin="3" topmargin="3" marginheight="3" marginwidth="3">
<TABLE WIDTH="100%" CELLPADDING=10 CELLSPACING=0 BORDER=0>
<TR>
<TD class="tt2" bgcolor="#F5F8F8" width="84%"><center><B><FONT style="FONT-SIZE: 16.5pt" COLOR="#FF6666" FACE="楷體_GB2312">統計中英文字個數</FONT></B></center>
<hr color="#EE9B73" size="1" width="94%">
<p class="tt2">想在文本控件TMemo中,分別對中、英文的字符數進行統計,我們可以通過把字符轉換為數值來進行判斷,Ord()函數把字符轉換為對應的數值,值33-126為鍵盤可使用字符,值127以上的為未知字符,即為漢字<br>
procedure TForm1.Button1Click(Sender: TObject);<br>
var s:string;<br>
i,e,c:integer;<br>
begin<br>
s:=memo1.text;<br>
e:=0;c:=0;<br>
for i:=1 to length(s) do<br>
begin<br>
if (ord(s[i])>=33)and(ord(s[i])<=126) then<br>
begin<br>
inc(e);<br>
label1.caption:='英文個數:'+inttostr(e);<br>
end<br>
else<br>
if (ord(s[i])>=127) then<br>
begin<br>
inc(c);<br>
label2.caption:='中文個數:'+inttostr(c div 2);<br>
end;<br>
end;<br>
end;</p>
<hr color="#EE9B73" size="1" width="94%">
</TD>
</TR>
</table>
</BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -