There are now many text processing software to implement text statistics. If we can do a small program to achieve this function, is it more meaningful? First, programming ideas: The program converts all characters in the MEMO control to the corresponding value by calling the ORD function, and then get the number of characters in MEMO through the length, and then judge each by for i: = 1 to length (s) DO The character value corresponding to the byte is between 33 to 126 to determine if the English characters (the number of Chinese characters are one of them, divided by one by 2). Second, the programming step: First, create a new project, save it, the Form1's CAPTION property is set to "Word Count Statistics", add 3 Label from the Standard page, and its CAPTION attribute is: "Please enter text", "alphabet" And "Chinese characters", and set the Color property to "CLBLACK". Add a MEMO control, set the color property to "clmoneygreen", the name property is "Memo1", the scrollbars property is "SSVertial", add the Button control 4, set their Caption as: "Paste text", "Start Statistics" and "Start Statistics" Exit emption. Finally, add 2 EDIT controls, and set the Color property to "ClmoneyGreen". FIG an operating screen three complete program code unit Unit3; interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; typeTForm1 = class (TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; memo1: TMemo; Button1: TButton; Button2: TButton; Edit1: TEdit; Edit2: TEdit; Button3: TButton; Button4: TButton; procedure Button2Click (Sender: TObject); procedure Button1Click (Sender: TObject); procedure Button3Click (Sender: TObject ); procedure Button4Click (Sender: TObject); private {Private declarations} public {public declarations} end; varForm1: TForm1; implementation {$ R * .dfm} procedure TForm1.Button2Click (Sender: TObject); vari, e, c: Integer; s: string; begins: = memo1.text; E: = 0; C: = 0; for i: = 1 to length (s) DOBEGINIF (ORD (S [i])> = 33) AND (ORD S [i]) <= 126) THENBEGININC (E); Edit1.Text: = INTOSTOSTR (E); endelseif (ORD (S [i])> = 127) Thenbegininc (c); edit2.text: = INTOSTR (C DIV 2); end; end;
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); BeginMemo1.PastefromClipboard; End;
Procedure TForm1.Button3Click (sender: Tobject); beginMemo1.clear; edit1.clear; ed; ed; process; beginclose; end; end;