Solved

string handling

Posted on 2004-04-01
10
191 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
 

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

12 Experts available now in Live!

Get 1:1 Help Now