Compare 2 strings

I have 2 strings (100 chars max).
The first line is the reference.
The second is introduced to the keyboard by a student.

How to count *all* the errors in the second line?

Ex :
1=The first line is the reference.
==================================
2=Thhe first lineis the reference. (2 errors)
2=Thehehe first line is the reference. (4 errors)
2=te first line is the eference. (3 errors)

Here is your answer. Go on extracting the substrings from the first and the second strings and compare them. I assume that there are two edit boxes and a button for starting the comparison process. I have done a simple comparison between the extracted strings. You can make it much more complicated and add counters to count errors. To achieve this, I have first developed a function called extract which I later use on the ButtonClick event.

This answer was to help you, not exactly to solve your problem or earn me points. We do develop a lot of parsers and tokenisers. We first break down the whole text into tokens and positions and then we parse/group/verify/(whatever is needed to be done) with the tokens. This happens to be the core code for extracting tokens - whether it is Pascal or C. Hope you enjoyed it.

4. The beauty of this method is that you actually can count
different errors!
5. Haven't checked the code, so if it doesn't work, let me know
and I'll put everything together.

Have fun,
c.u. ZifNab;

0

jpdupontAuthor Commented: 1997-09-25

Thank you for your proposal.
Unfortunately, as I explained, the problem is more complex. Your function gives me no precise result.

With your function, try :

1=papa
2=paa ( 1 error [paPa])

Your function give me 3 errors !!!

My analysis of the problem is the following:
1) I loop the 2 lines until the first error.
2) The error can be:
- a letter lacks
- a letter to much
- a bad letter

3) Tests
- I copy the line 2 in 3 temporary strings
- I test each these 3 strings by correcting them 3 different manners according to the possible error type. I seek in the 3 strings where is found the next error. The largest result should give me the correct error type.
That functions correctly *sometimes* !
Would you like to see my code ?

If what I ask is too difficult, an acceptable solution would be
to verify word by word.

!!!
- The student can have forgotten a space between 2 words.
- The student can have forgotten a word.

Ex.

1=An acceptable solution would be to verify word by word.

2=Anacceptable solution would be to verify word by word. (=1 error ->Space between the 2 first words - all the others are correct)
2=An aceptable solution would be to verify word by word. (=1 error ->acCeptable - easy : all the words are in the correct position)
2=An acceptable solution would to verify word by word. (=1error ->BE)
2=An acceptable solution would beto verify word by wrd. (=2 errors -> space between BE and TO, wOrd)

function WordCount(s:string):integer;
var I : Word;
begin
Result := 0;
I := 1;
while I <= Length(s) do begin
while (I<=Length(s)) and (S[I]=' ') do
Inc(I);
if I<=Length(s) then
Inc(Result);
while (I<=Length(s)) and not(S[I]=' ') do
Inc(I);
end;
end;