The number of English words in Delphi programming statistics

Source: Internet
Author: User
Tags ord

Chinese use of Chinese characters, but also mixed with these English, so that we in the number of trouble, the computer is measured in bytes, a Chinese character count two words, and the Chinese custom is a Chinese character is a word, so the computer to calculate must solve the following problems:

Using text control TMemo to store articles, the number of characters in both Chinese and English is counted, we can judge by converting the characters into ASCII values, the ORD () function can convert the characters to corresponding values, the value 33-126 is the keyboard can use the character, the value 127 is the unknown character, is the Chinese character.

procedure TForm1.Button1Click(Sender: TObject);
var s:string;
i,e,c:integer;
begin
s:=memo1.text;
e:=0;c:=0;
for i:=1 to length(s) do
begin
if (ord(s[i])>=33)and(ord(s[i])<=126) then
begin
inc(e);
label1.caption:=英文字数:+inttostr(e);
end
else
if (ord(s[i])>=127) then
begin
inc(c);
label2.caption:=中文字数:+inttostr(c div 2);
end;
end;
end;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.