Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Delphi, RichEdit, Find method

Posted on 2011-02-18
10
Medium Priority
?
1,538 Views
Last Modified: 2012-05-11
Hi,
I Have a Special requirement. I am Using Delphi 7. I am loading some text/RTF files on RichEdit Component. I am hi liting the searched Word on the RichEdit.

For Example, I am Searching for "SQL Server", it Shows the Words in RTF. My Requirement is I have to Select Not only the given Words, Also select if there is any Special symbols within the Words. like "SQL.Server","SQL-Server" etc.

Thanks and Regards,
VIJESH V.NAIR
0
Comment
Question by:OTSSolutions
[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
10 Comments
 
LVL 24

Accepted Solution

by:
jimyX earned 1000 total points
ID: 34925111
You can add all the special symbols that you expect in an array and search by replacing any space or non-alphabetic char in the phrase you want to find by substituting from that array one by one until you find and highlight all the similarities:
var // global var
  SpecialChar:array [1..3]of char = ('-','.','_'); // you can add any additional symbols

procedure TForm1.FindText(FindStr: string);
var X, ToEnd : integer;
    oldCursor : TCursor;
begin
   oldCursor := Screen.Cursor;
   Screen.Cursor := crHourglass;
   with RichEdit1 do
   begin
     X := 0;
     ToEnd := length(Text) ;
     X := FindText(FindStr, X, ToEnd, []) ;
     while X <> -1 do
     begin
     SetFocus;
     SelStart := X;
     SelLength := length(FindStr) ;
     SelAttributes.Color := clRed;
     X := FindText(FindStr,X + length(FindStr),ToEnd, []);
     end;
   end;
   Screen.Cursor := oldCursor;
end;

function SpecialSymbol(Ch:Char):Boolean;
begin
  if  Ch in ['a'..'z','A'..'Z'] then
    Result := False
  else
    Result := True;
end;

procedure TForm1.Button1Click(Sender: TObject) ;
var
   Str: string;
   i, j:integer;
begin
   Str := 'SQL Server';
   FindText(Str);

   for i:= 1 to length(Str) do
     begin
       if SpecialSymbol(Str[i]) then
         begin
           for j:= 1 to high(SpecialChar) do
             begin
               Str[i] := SpecialChar[j];
               FindText(Str);
             end;
         end;
     end;
end;

Open in new window

I am using the Search Function from:
http://delphi.about.com/cs/adptips2003/a/bltip0803_2.htm
0
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 1000 total points
ID: 34939795

For wild card searches, you need to use regular expressions.
Download and install TRegEx or TPerlRegEx

Using it is very easy, just set the expression, in your case could be SQL?Server
The ? will represent any character
0
 

Author Comment

by:OTSSolutions
ID: 34941685
Ok,
Thanks jimyX, and ewangoya:

Will get back to you
0
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!

 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35180438

I have already pointed the Author to the correct direction using Regular Expressions which can be downloaded from
http://www.regular-expressions.info/delphi.html.
Thats the way to search using wild cards
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35224456
I have provided a working solution to the author's question!
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35237248
I will not object to this but just make a note

This is class, CS Analysis of Algorithms
You have a classic example of pattern matching here, while putting in effort to develop a solution, research should be properly done on a problem before attempting to formulate a solution.

This type of question is the exact reason why we have Regular Expressions. TPerlRegEx and TRegEx are thoroughly tested and time proven methods for solving such problems.

One of the basis of OO is code reuse so we don't have to re_invent the wheel and a solution using such loops is not forward thinking neither is it expected to work under all conditions. This is the kind of coding where you have to create new application builds everyweek because some one added another search character to a search
0
 

Expert Comment

by:South Mod
ID: 35292442
All,
 
Following an 'Objection' by jimyX (at http://www.experts-exchange.com/Q_26914116.html) to the intended closure of this question, it has been reviewed by at least one Moderator and is being closed as recommended by the Expert.
 
At this point I am going to re-start the auto-close procedure.
 
Thank you,
 
SouthMod
Community Support Moderator
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

688 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