How to recognize the misspelled

Posted on 2009-02-18
Medium Priority
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 38

Accepted Solution

Geert Gruwez earned 2000 total points
ID: 23692235
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


Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

862 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