how to check more than one char

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

LVL 7
tankergoblinAsked:
Who is Participating?
 
MerijnBSr. Software EngineerCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.