954,123 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Character/letter count

Hey all,

Would anyone be able to help me out with some code to count how many characters there are in a string e.g.

A label disaplys the number of characters that the user has typed into a memo.

Katrix36

Katrix36
Newbie Poster
16 posts since Jan 2006
Reputation Points: 10
Solved Threads: 0
 

Hi,

If you count the white spaces and CRs and LFs as character too, you can simply use Edit1.Text := IntToStr(Len(Memo1.Text)); to show the number of chars on Edit1 and if you put the above code on Memo1's OnChange then it will show the char count at real time as the user writes.

Loren Soth

Lord Soth
Posting Whiz in Training
233 posts since Mar 2006
Reputation Points: 28
Solved Threads: 4
 

try the following, to count the number of letters in a particular line(0)

[procedure TForm1.Button1Click(Sender: TObject);
var
a:Integer;
begin
a:=length(Memo1.Lines[0]);
label1.Caption:=IntToStr(a);
end;]
 
or to count the number of total letters (in fact characters)
[procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c:Integer;
begin
a:=length(Memo1.Lines[0]);
label1.Caption:= IntToStr(length(Memo1.Lines.Text)) ;
end;]
daycartes
Newbie Poster
5 posts since Apr 2006
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You