| | |
pascal word and letter counting
![]() |
•
•
Join Date: Oct 2006
Posts: 1
Reputation:
Solved Threads: 0
hey
I am learning pascal and need to write a program where, when the user enters a sentence finishing with a full stop it prints the number of words in the sentance and the number of words with over 3 letters in.
I have no idea how to count the words in a sentance or the letters in a word. I also dont no how to regonise the full stop as the end of the sentence. So as you can see im quite stuck!
Any help getting started would be much appreciated
tom
I am learning pascal and need to write a program where, when the user enters a sentence finishing with a full stop it prints the number of words in the sentance and the number of words with over 3 letters in.
I have no idea how to count the words in a sentance or the letters in a word. I also dont no how to regonise the full stop as the end of the sentence. So as you can see im quite stuck!
Any help getting started would be much appreciated
tom
•
•
•
•
hey
I am learning pascal and need to write a program where, when the user enters a sentence finishing with a full stop it prints the number of words in the sentance and the number of words with over 3 letters in.
I have no idea how to count the words in a sentance or the letters in a word. I also dont no how to regonise the full stop as the end of the sentence. So as you can see im quite stuck!
Any help getting started would be much appreciated
tom
•
•
Join Date: Oct 2006
Posts: 3
Reputation:
Solved Threads: 0
If you need help getting started, These are Code Blocks I'd use:
To get the length of a string:
To get only the string until the full stop:
To count the number of letters:
I'll have to think about how to count the number of words with over three letters, though - I'll try to post it tomorrow.
Greetz
WhiteAvenger
To get the length of a string:
pascal Syntax (Toggle Plain Text)
length(<somestring>) {This gives you - have a guess - the Length of a string.}
To get only the string until the full stop:
pascal Syntax (Toggle Plain Text)
var ct:Integer; somestring, croppedString:String; Flag:Boolean; ... Begin ... Flag := False; ct:= 0; While not Flag Do Begin Inc(ct); Flag := (somestring[ct] = '.') or (ct = length(somestring)); {somestring[2] gives you the 2nd letter of the string.} End; croppedString:= copy(somestring, 1,ct); {copy(String, Index, Count) gives you the "count" letters after "Index".} ... End.
To count the number of letters:
pascal Syntax (Toggle Plain Text)
var ct,NumOfLetters: Integer; somestring: String; ... Begin ... NumOfLetters := 0; For ct:= 1 to length(somestring) Do If (somestring[ct] <> ' ') Then Inc(NumOfLetters); {Increase NumOfLetters.} ... End.
I'll have to think about how to count the number of words with over three letters, though - I'll try to post it tomorrow.
Greetz
WhiteAvenger
![]() |
Similar Threads
- Fantastic Word Game-2 (Posting Games)
- Word Descrambler.... (C++)
- Guess a word (Python)
- word unscrambler (Python)
- Exceptions (Java)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: Compound Control Class
- Next Thread: Dialog Box Problem
| Thread Tools | Search this Thread |





