Avatar of KLOPEKS
KLOPEKS

asked on 

string handling

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;
Delphi

Avatar of undefined
Last Comment
KLOPEKS
Avatar of kretzschmar
kretzschmar
Flag of Germany image

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 ;-)

Avatar of kretzschmar
kretzschmar
Flag of Germany image

oops some brackets missed
corrected:

     if not (strlst[i] = 'god') then  // ??? just a guess
     
Avatar of esoftbg
esoftbg
Flag of Bulgaria image

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

emil
Avatar of KLOPEKS
KLOPEKS

ASKER

how can i exclude more than one string?
Avatar of esoftbg
esoftbg
Flag of Bulgaria image

oops:
For i := 0 To strlst.Count-1 Do
Avatar of esoftbg
esoftbg
Flag of Bulgaria image

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;
Avatar of kretzschmar
kretzschmar
Flag of Germany image

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 ;-)
Avatar of KLOPEKS
KLOPEKS

ASKER

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;
ASKER CERTIFIED SOLUTION
Avatar of esoftbg
esoftbg
Flag of Bulgaria image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of KLOPEKS
KLOPEKS

ASKER

thanks, you both are a great help!
Delphi
Delphi

Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Development™. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.

60K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo