Link to home
Start Free TrialLog in
Avatar of Dennis9
Dennis9

asked on

Text searching ??

Hi.

I have a listbox with some items in.
I need to create a procedure that will check all the words in the listbox, for mitiply instances.


Example: (listbox items)

Hello Everyone in here
yeah hello
This is a test

so the procedure start by extracting all words in the first sentence "Hello" then it moves though the listbox to see if it do exists other places. If the given word exist in a line i would just like it to show a message :)

Okay hope u get me.
Thanks
 Dennis
Avatar of Cynna
Cynna

Well, I'm not quite sure if this is what you want...

Place Button1 and ListBox1 on the Form1:

Copy/Paste:
----------------

procedure TForm1.Button1Click(Sender: TObject);
var i: Integer;
    What, Line: String;
begin
  // What do you want to find:
  What:='hello';
  // Case insensitive search:
  What:=LowerCase(What);
  for i:=0 to ListBox1.Items.Count-1 do begin
      Line:=LowerCase(ListBox1.Items.Strings[i]);
      if Pos(What, Line)>0 then ShowMessage(What+' found in line #'+IntToStr(i));
  end;
end;
You want to see if a word is somewhere in a listbox?

function SearchListBox(textToSearchFor: string): Boolean;
var
I: Integer;
begin
Result := false;
for I := 0 to yourListBox.Items.Count - 1 do
begin
    if Pos(textToSearchFor, yourListBox.Items[I]) <> 0 then
       begin
         Result := true; // textToSearchFor found in item I
         // Put some more code here if you want
         break; // If the word is found, exit the for-loop. If you want to continue searching after the first occurence is found, remove this.
       end;  
end;
end;

This function returns true if the text/word was found, and false if not.
woops! U were first, Cynna :) I guess I have to work on my typing skills.
:))
Avatar of Dennis9

ASKER

The text to search for is the listboxs own words. It should extract every word between " " (space) and try a search and see if it exists other places in the list
Avatar of Dennis9

ASKER

The text to search for is the listboxs own words. It should extract every word between " " (space) and try a search and see if it exists other places in the list
Sorry, I still don't understand exactly what you need...

Do you want to extract every word of every line, and then search for duplicates?

Please try to be more elaborate.
Avatar of Dennis9

ASKER

yup Cynna exactly, and if more than 2 dupes are found just show a message
Try this, much easier:


var list:AnsiString;
begin
   List:=Listbox1.items.Commatext;
   while pos('hello',List)>0 do Delete(List,pos('hello',List),5);
   Listbox1.Items.commatext:=List;
end;



Good luck!!
ASKER CERTIFIED SOLUTION
Avatar of david-johnstone
david-johnstone

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dennis9

ASKER

david-johnstone -> Thanks just what i needed.

Thanks again everyone.

Avatar of kretzschmar
in this case,
you should david-johnstone's accept comment as answer
Dennis9:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
Dennis9,
No comment has been added lately (18 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to david-johnstone http:#7131879

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

anAKiN
EE Cleanup Volunteer