Solved

string handling

Posted on 2004-04-01
10
193 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now