unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
// 실제 글자수를 조사하는데 Length() 함수는 사용할 수 없습니다.
// 문자열이 반각만 인 경우는 Length() 함수로도 옳은 결과를
// 돌려주지만, 전각문자가 혼재된 경우는 실제의 글자수보다
// 많은 값을 돌려줍니다. 그것은 Length() 함수는 글자수가 이닌
// 바이트수를 돌려주는 함수이기 때문입니다.
// 실제 글자의 수를 조사하기에는 ByteToCharLen() 함수를 사용하는데
// 이 함수는 두개의 인수가 필요한데 첫번째는 조사하는 문자렬,
// 다음에는 조사하는 길이입니다. 통상은 Length() 값을 줍니다
procedure TForm1.Button1Click(Sender: TObject);
begin
{바이트수}
Label1.Caption := IntToStr(Length(Edit1.Text));
{문자수}
Label2.Caption := IntToStr(ByteToCharLen(Edit1.Text, Length(Edit1.Text)));
end;
end.