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

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

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;]
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.