Note that there are some explanatory texts on larger screens.

plurals
  1. PONotepad++ .NET plugin - get current buffer text -- encoding issues
    primarykey
    data
    text
    <p>I have a .NET plugin which needs to get the text of the current buffer. I found this <a href="http://sourceforge.net/p/notepad-plus/discussion/482781/thread/90ae2b1a/" rel="nofollow">page</a>, which shows a way to do it:</p> <pre><code>public static string GetDocumentText(IntPtr curScintilla) { int length = (int)Win32.SendMessage(curScintilla, SciMsg.SCI_GETLENGTH, 0, 0) + 1; StringBuilder sb = new StringBuilder(length); Win32.SendMessage(curScintilla, SciMsg.SCI_GETTEXT, length, sb); return sb.ToString(); } </code></pre> <p>And that's fine, until we reach the character encoding issues. I have a buffer that is set in the Encoding menu to "UTF-8 without BOM", and I write that text to a file:</p> <pre><code>System.IO.File.WriteAllText(@"C:\Users\davet\BBBBBB.txt", sb.ToString()); </code></pre> <p>when I open that file (in notepad++) the encoding menu shows UTF-8 without BOM but the <code>ß</code> character is broken (ß).</p> <p>I was able to get as far as finding the encoding for my current buffer:</p> <pre><code>int currentBuffer = (int)Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETCURRENTBUFFERID, 0, 0); Console.WriteLine("currentBuffer: " + currentBuffer); int encoding = (int) Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETBUFFERENCODING, currentBuffer, 0); Console.WriteLine("encoding = " + encoding); </code></pre> <p>And that shows "4" for "UTF-8 without BOM" and "0" for "ASCII", but I cannot find what notepad++ or Scintilla thinks those values are supposed to represent.</p> <p>So I'm a bit lost for where to go next (Windows not being my natural habitat). Anyone know what I'm getting wrong, or how to debug it further?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload