Solved

string handling

Posted on 2004-04-01
10
195 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
Industry Leaders: 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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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