Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how to check more than one char

Posted on 2009-02-15
1
Medium Priority
?
314 Views
Last Modified: 2013-11-23
I have following text " i ADN you Adn him adn her"

I only can correct last text adn which is "i ADN you Adn him and her"

i know this will happen because variable "text" will overwrite itself.
How to make my code able to read ADN,Adn and adn?

My code is below...
Type
TCharMisspelled = (ADN,NAD,DNA)
 
procedure example.CheckChar(TextString:string;Type:TCharMisspelled); 
var
text: string;
begin
 Case Type of
 ADN:
    if (AnsiContainsStr(TextString,'ADN')) or (AnsicontainsStr(TextString,'Adn'))or(AnsiContainsStr(TextString,'adn')then
    begin
    //problem:read only adn
    text := AnsiReplaceString(TextString,'ADN','and');
    text := AnsiReplaceString(TextString,'Adn','and');
    text := AnsiReplaceString(TextString,'adn','and');
    //i load back checked string to Memo
    Memo.text:=text;
    end;
 end;
end;
 
 
procedure example.CheckClick(Sender: TObject);
var
Text:string;
begin
//I have a string in my Memo
Text:=Memo.Text;
//call CheckChar
CheckChar(Text,ADN);
end;

Open in new window

0
Comment
Question by:tankergoblin
1 Comment
 
LVL 19

Accepted Solution

by:
MerijnB earned 2000 total points
ID: 23647596
You should use AnsiReplaceText() in stead of AnsiReplaceStr(). AnsiReplaceText() is case insensitive, so it will fix all occurrences at once.
Type
TCharMisspelled = (ADN,NAD,DNA)
 
procedure example.CheckChar(TextString:string;Type:TCharMisspelled); 
var
text: string;
begin
 Case Type of
 ADN:
    if (AnsiContainsStr(TextString,'ADN')) or (AnsicontainsStr(TextString,'Adn'))or(AnsiContainsStr(TextString,'adn')then
    begin
    //problem:read only adn
    text := AnsiReplaceText(TextString,'adn','and');
    //i load back checked string to Memo
    Memo.text:=text;
    end;
 end;
end;
 
 
procedure example.CheckClick(Sender: TObject);
var
Text:string;
begin
//I have a string in my Memo
Text:=Memo.Text;
//call CheckChar
CheckChar(Text,ADN);
end;

Open in new window

0

Featured Post

Technology Partners: 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

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

580 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