Solved

string handling

Posted on 2004-04-01
10
196 Views
Last Modified: 2010-04-05
I have a TStringList that contains a list of strings like:

sex
drugs
god
rocknroll

Then i have a procedure that does something for each string in the list with each string in the list,
But i dont need to do it if the string that is indexed contains the the text 'god' or multiple strings i specify,
how do i do that?, I have only programmed in Delphi for 6 months.

begin
  strlst := TStringList.Create;
  strlst.LoadFromFile('c:\file.txt');
end;
begin
  For i := 0 To strlst.Count Do if not strlst[i] = 'god';  // ??? just a guess
  Begin
    bla := ( strlst[i] );
end;
0
Comment
Question by:KLOPEKS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10730922
begin
  For i := 0 To strlst.Count -1 Do
     if not strlst[i] = 'god' then  // ??? just a guess
     Begin
       bla := ( strlst[i] );
     end;
end;

meikl ;-)

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10730926
oops some brackets missed
corrected:

     if not (strlst[i] = 'god') then  // ??? just a guess
     
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10730946
For i := 0 To strlst.Count Do
  if (Pos('god', strlst[i]) = 0) then  
  begin
    bla := ( strlst[i] );
  end;

emil
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:KLOPEKS
ID: 10730950
how can i exclude more than one string?
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10730954
oops:
For i := 0 To strlst.Count-1 Do
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10730963
how can i exclude more than one string?
In anoter stringList ;-))

For i := 0 To strlst.Count-1 Do
  if (Pos('god', strlst[i]) = 0) then  
  begin
    slst.Add(strlst[i] );
  end;
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10730969
you can have two stringlists, for ex.

add in the seond stringlist the words, which should not act

your evaluation-routine should the show like

begin
  for i := 0 to List1.count-1 do
    if list2.indexof(list1[i]) = -1 then
      bla := list1[i];
end;

meikl ;-)
0
 

Author Comment

by:KLOPEKS
ID: 10731002
so if i wanted to [not] do the procedure for more than one string i should use ?

For i := 0 To strlst.Count Do
  if (Pos('god', strlst[i]) = 0) then  
 if (Pos('sex', strlst[i]) = 0) then
  begin
    bla := ( strlst[i] );
  end;
0
 
LVL 12

Accepted Solution

by:
esoftbg earned 250 total points
ID: 10731012
For i := 0 To strlst.Count-1 Do
  if (Pos('god', strlst[i]) = 0) then  
 if (Pos('sex', strlst[i]) = 0) then
  begin
    bla := ( strlst[i] );
    break;
  end;
0
 

Author Comment

by:KLOPEKS
ID: 10731024
thanks, you both are a great help!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question