Main Logo
Articles   Members Online:
-Article/Tip Search
-News Group Search over 800,000 Borland news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Delphi: How to get the number of Words in a string?
Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to get the number of Words in a string? Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
count the number of words in a string 16-Mar-04
Category
VCL-General
Language
Delphi All Versions
Views
594
User Rating
9.5
# Votes
2
Replies
1
Publisher:
Paul, Jean
Reference URL:
			The following function can be used to get the number of words in a string.
  Call the function like ShowMessage(IntToStr(GetWordCount('test string, 1 2 3')));
1   
2     //Function starts here
3     function GetWordCount(const SourceStr: string): Longint;
4     var
5       i, len: Longint;
6       WordSeparators: string;
7     begin
8       Result := 0;
9       WordSeparators := ' ,.;'; { If needed then add more string separators }
10      i := 1;
11      len := Length(SourceStr); { Get the length of source string and assign to a 
12  variable }
13      while i <= len do
14      begin
15        if Pos(SourceStr[i], WordSeparators) = 0 then
16        { i.e  currenct char is a valid word character like a, b, c etc. }
17        begin
18          { Enter a loop that will end if a word separator charcter like ., space 
19  etc. found }
20          while (i <= len) and (Pos(SourceStr[i], WordSeparators) = 0) do
21            Inc(i);
22          Inc(Result);
23        end;
24        Inc(i);
25      end;
26    end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC
Advertisement


Share this page
Advertisement
Copyright © 2017 by No Limit Solutions LLC