How to recognize the misspelled

Posted on 2009-02-18
Last Modified: 2012-05-06
i have a string of text
text = "how are ouy. Where are uyo from. Can you give me your contact"

first i need to correct the word you then i need to mark the corrected "you" with color green but how?

if i use
richedit1.selStart := posEx('you',richedit1.text,richedit1.selstart)-1;
richedit1.selLength := Length('you');
richedit1.selAttribute.color := clGreen;

i will turn all word 'you' to green color.

How to turn only "misspelled" you to green.

my code as below

correctedText : string;

richedit1.text := "how are ouy. Where are ouy from. Can you give me your contact"

correctedText := AnsiReplaceText(richedit1.text,'ouy','you');


richedit1.selStart := posEx('you',richedit1.text,richedit1.selstart);

if richedit1.selStart <> 0 then


richedit1.selStart := posEx('you',richedit1.text,richedit1.selstart)-1;

richedit1.selLength := Length('you');

richedit1.selAttribute.color := clGreen;

richedit1.selStart := richedit1.selStart +1;


until richedit1.selStart = 0;

Open in new window

Question by:tankergoblin
    1 Comment
    LVL 36

    Accepted Solution

    well first, you need a dictionary to know the misspelling ... wrong word --> correct word

    a simple TStringList would be possible:

    List := TStringList.Create;
      List.Values['YUO'] := 'YOU';
      List.Values['OYU'] := 'YOU';

      correctedText : string;
      List: TStringList;
    richedit1.text := "how are ouy. Where are ouy from. Can you give me your contact"
    // you need to find every wrong word, mark it one by one, and replace it one by one
    n := 1;
    for I := 0 to List.Count-1 do  
      wrongword := List.Names[I];
      correctword := List.ValueFromIndex[I];
        n := PosEx(wrongword, richedit1.text, n);
        if n > 0 then 
          RichEdit1.SelStart := n; // select the wrongword
          RichEdit1.SelLength := Length(WrongWord);
          RichEdit1.SelText := CorrectWord;  // replace with the correct word
          RichEdit1.SelStart := n;// reselect the correct word
          RichEdit1.SelLength := Length(CorrectWord); 
          richedit1.selAttribute.color := clGreen; // change the color
          n := n +1;
      until n = 0;

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
    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…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now