Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Text searching ??

Posted on 2002-07-05
14
Medium Priority
?
184 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:Dennis9
[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
  • 2
  • +5
14 Comments
 
LVL 7

Expert Comment

by:Cynna
ID: 7131711
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;
0
 
LVL 1

Expert Comment

by:herr_apfelschnitt
ID: 7131725
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.
0
 
LVL 1

Expert Comment

by:herr_apfelschnitt
ID: 7131728
woops! U were first, Cynna :) I guess I have to work on my typing skills.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 7

Expert Comment

by:Cynna
ID: 7131734
:))
0
 
LVL 1

Author Comment

by:Dennis9
ID: 7131737
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
0
 
LVL 1

Author Comment

by:Dennis9
ID: 7131740
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
0
 
LVL 7

Expert Comment

by:Cynna
ID: 7131764
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.
0
 
LVL 1

Author Comment

by:Dennis9
ID: 7131800
yup Cynna exactly, and if more than 2 dupes are found just show a message
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 7131854
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!!
0
 

Accepted Solution

by:
david-johnstone earned 400 total points
ID: 7131879
OK, try this!!!

procedure TForm1.Button1Click(Sender: TObject);
var
  Temp, Current, Prev: String;
  slTemp: TStringList;
  i: Integer;
  SentMessage: Boolean;
begin
  Temp := ListBox1.Items.CommaText;
  Temp := StringReplace(Temp, ' ', ',', [rfReplaceAll]);
  Temp := StringReplace(Temp, '"', '', [rfReplaceAll]);

  slTemp := TStringList.Create;
  slTemp.CommaText := Temp;
  slTemp.Sort;

  Prev := '';

  for i := 0 to slTemp.Count - 1 do
  begin
    Current := slTemp.Strings[i];

    if (Uppercase(Current) = Uppercase(Prev)) then
    begin
      if not SentMessage then
      begin
        ShowMessage('Duplicate - ' + Current);
        SentMessage := True;
      end;
    end
    else
      SentMessage := False;

    Prev := Current;
  end;

  slTemp.Free;
end;

This seperates all the items of the list box into comma seperated words.  They are then loaded into another string list and sorted alphabetically.  It is then a case of looping through to find any duplicates.  I've put Uppercase() around the comparison part to make it case insensitive.  If you need a case sensitive comparison, then just remove them...

Hope that helps!

David.
0
 
LVL 1

Author Comment

by:Dennis9
ID: 7131949
david-johnstone -> Thanks just what i needed.

Thanks again everyone.

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7132573
in this case,
you should david-johnstone's accept comment as answer
0
 

Expert Comment

by:CleanupPing
ID: 9343101
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.
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 9460205
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
0

Featured Post

Independent Software Vendors: 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

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…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

730 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