Find&Replace ERROR in Utf-8 format for Chinese

Topics: Developer Forum
Dec 6, 2010 at 1:01 PM

Hi ! First , thx a lot for this great work !

I'd like use ScintillaNET  to develop an editor for training Chinese in Utf-8 format.

But , in my test , I found that , the internal Find&Replace cann't work right.

When I try to find a Chinese word , such as "企业", it will find it , but , the highting-selection  in the edtior would be only half of the word.

However , I've found that , in the source file 'FindReplace.cs' , there is a setence like this:

        return new Range(pos, pos + searchString.Length, Scintilla);

I thought, the problem may be that, 'searchString.Length' counted in Utf-8 format should be 2, but in byte-format should be 4.

I tried to change this sentence to be:

      return new Range(pos, pos + Scintilla.Encoding.GetByteCount(searchString), Scintilla);

It doesn't work!

I'm a fresher for C# . If anyone could help me to find the real problem?

Thx a lot!

Dec 6, 2010 at 1:03 PM

Oh ,bye the way,  I'm so SORRY for my poor English !

thanks again

Nov 17, 2011 at 2:57 AM
Edited Nov 17, 2011 at 2:57 AM

Hi peter I catch same problem. I fix file 'FindReplace.cs' ->Find Function like this(Attention red color). 


public unsafe Range Find(int startPos, int endPos, string searchString, SearchFlags flags)
	TextToFind ttf = new TextToFind();
	ttf.chrg.cpMin = startPos;
        ttf.chrg.cpMax = endPos;

       fixed (byte* pb =Scintilla.Encoding.GetBytes(searchString))
	  ttf.lpstrText = (IntPtr)pb;
	  int pos = NativeScintilla.FindText((int)flags, ref ttf);
	  if (pos >= 0)
               return new Range(pos, pos + Scintilla.Encoding.GetByteCount(searchString), Scintilla);
	     return null;

perhaps with you same. But run right!