Text.Length!=currentPos

Topics: Developer Forum, Project Management Forum, User Forum
Dec 8, 2009 at 2:58 AM

private void Form2_Load(object sender, EventArgs e)
        {
            scintilla1.NativeInterface.SetCodePage(65001);
        }

for example:
scintilla1.text = "abc中文";
The cursor at last。
now : scintilla1.Text.Length =5  but currentPos = 9
please help me!!!

Dec 8, 2009 at 3:00 AM

the scintillaNet is 2.2.0.0

Developer
Dec 8, 2009 at 9:24 AM

Hey,

I had the same problem, what exactly do you want t do?

The reason why currentPos is 9, is that scintilla returns the byte count with its currentPosition not the real word count.

You could use the Method

GetWordFromPosition(Position)

to get the word of your position.

Best Regards

Dec 8, 2009 at 9:46 AM

 Klingel , Thank you very much !

Coordinator
Dec 8, 2009 at 7:47 PM

Klingel is correct. When talking about positions and lengths Scintilla usually means bytes, not characters. Scintilla's Unicode handling is always UTF-8 which means that ASII ranged characters take 1 byte and extended characters are 2-4 bytes. Scintilla.Text.Length will return character length because the Scintilla.Text is a .NET UTF-16 string, .Length always returns the number of characters. If you want to get the length in bytes use Scintilla.TextLength.