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 access duplicates in a TStringList 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
20-Oct-02
Category
Object Pascal-Strings
Language
Delphi 2.x
Views
77
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

I have a TStringList that looks something like:

a = one
b = two
c = three
c = four

Could someone please tell me to access both values of c? When I try to use 
(StringList.Values['c']) to get the value of c, I can only ever get the first 
value, and I need both. Even looping through every item in the list would be fine, 
but I can't get that to work either. StringList[I] in a for loop only gives me the 
whole line, like c=three, and I just want the value three.

Answer:

Solve 1:
1   
2   procedure GetMatchingValues(strKey: string; slSource, slResult: TStringList);
3   var
4     i, nStart: integer;
5   begin
6     slResult.Clear;
7     strKey := strKey + '=';
8     nStart := Length(strKey) + 1;
9     for i := 0 to slSource.Count - 1 do
10    begin
11      if Pos(strKey, slSource[i]) = 1 then
12        slResult.Add(Copy(slSource[i], nStart, Length(slSource[i])));
13    end;
14  end;



Solve 2:

Try something like the following:

15  for i := 0 to SL.Count - 1 do
16  begin
17    temp := SL[i];
18    p := pos('=', temp);
19    key := copy(temp, 1, p - 1);
20    if key = 'c' then
21      value := copy(temp, p + 1, length(temp));
22  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