1. function CountWords(InputString: string): integer;
2. var
3. aChar: char;
4. WordCount: integer;
5. IsWord: boolean;
6. i: integer;
7. begin
8. WordCount := 0;
9. IsWord := False;
10. for i := 0 to Length(InputString) do
11. begin
12. aChar := InputString[i];
13. if (aChar in [
14. 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s',
15. 't','u','v','w','x','y','z',
16. 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S',
17. 'T','U','V','W','X','Y','Z',
18. '0','1','2','3','4','5','6','7','8','9','0','''','-'
19. ]) then
20. begin
21. if not IsWord then Inc(WordCount);
22. IsWord := True;
23. end
24. else if aChar = '\' then IsWord := True
25. else IsWord := False
26.
27. end;
28.
29. IsWord := False;
30. Result := WordCount;
31.end;
|