View previous topic :: View next topic |
Author |
Message |
Kevin Grandmaster Cheater Supreme
Reputation: 0
Joined: 07 Mar 2007 Posts: 1139 Location: Spiderman-World
|
Posted: Thu Aug 23, 2007 6:25 am Post subject: A label counting words... (Delphi) |
|
|
Im making a notepad program (for school use).
I want to be able to see how many words i used, how can i do this?
Also i want to be able to could count every single thing i post, ect:
1 2 3
Then the label would show 5, because the spaces is involved too...
If you don't get me i'll try to explain again.
|
|
Back to top |
|
 |
assaf84 Expert Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 238
|
Posted: Thu Aug 23, 2007 6:33 am Post subject: |
|
|
Let's say you put it all in a memo. What you need to do is loop all the lines, and in every line loop all the chars, and search for spaces. The number of words will be the number of spaces plus the number of lines plus 1. If you don't get it take some examples.
If you want to know the total number of chars just loop every line and every chars and count them.
|
|
Back to top |
|
 |
Kevin Grandmaster Cheater Supreme
Reputation: 0
Joined: 07 Mar 2007 Posts: 1139 Location: Spiderman-World
|
Posted: Thu Aug 23, 2007 6:35 am Post subject: |
|
|
could you give me an example code? not the full code or anything, just so i got something i can build it on. thanks
|
|
Back to top |
|
 |
assaf84 Expert Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 238
|
Posted: Thu Aug 23, 2007 6:49 am Post subject: |
|
|
Let's say the user writes in Memo1, char's count in Label1 and word's count in Label2.
In Memo2Change or something:
Code: |
var
i,j: Integer;
charCount: integer;
wordCount: Integer;
begin
wordCount = 0;
charCount = 0;
for i:=0 to Memo1.Lines.Count-1 do //I'm not sure, check it in delphi
begin
for j:=0 to Memo1.Lines[i].GetLength-1 do //I'm pretty sure it's not true, again, check it
begin
charCount := charCount+1;
if Memo1.Lines[i][j] = ' ' then
wordCount = wordCount + 1;
end;
wordCount = wordCount + 1;
end;
Label1.Caption := IntToStr(charCuont);
Label2.Caption := IntToStr(wordCuont);
end;
|
Hope this helps
|
|
Back to top |
|
 |
Kevin Grandmaster Cheater Supreme
Reputation: 0
Joined: 07 Mar 2007 Posts: 1139 Location: Spiderman-World
|
Posted: Thu Aug 23, 2007 7:05 am Post subject: |
|
|
It gave me an idea, but as you said some of it are wrong. but thanks!
|
|
Back to top |
|
 |
|