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 Parse Strings using TParser 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
21-Jan-03
Category
Object Pascal-Strings
Language
Delphi 2.x
Views
132
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: William Gerbert

Parsing Strings using TParser

Answer:

Delphi has a cool class called TParser that the IDE uses to parse the source code. 
You can also use it to parse strings.

This function takes a string argument and splits it into separate words for you.

1   procedure ParseThis(MyStr: string);
2   var
3     MyParser: TParser;
4     MS: TMemoryStream;
5   begin
6     MS := TMemoryStream.Create;
7     MS.Position := 0;
8     MS.write(MyStr[1], Length(MyStr));
9     MS.Position := 0;
10    MyParser := TParser.Create(MS);
11    MyStr := MyParser.TokenString;
12    ShowMessage(MyStr);
13    while MyParser.Token <> toEOF do
14    begin
15      MyParser.NextToken;
16      if MyParser.TokenSymbolIs(MyParser.TokenString) then
17      begin
18        MyStr := MyParser.TokenString;
19        ShowMessage(MyStr);
20      end;
21    end;
22    MyParser.Free;
23    MS.Free;
24  end;
25  
26  procedure TForm1.Button1Click(Sender: TObject);
27  begin
28    ParseThis('Now is the time for all men to come to the aid of their country.');
29  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