Donate

Notepad++ Plugin GetText Method Not Getting Entire String In C#

Good evening,

We have this Notepad++ Plugin project that will read and parse an html document converted from a MS Word file and then change the html string into an Adobe In Design format. The issue is that the html document has over 20,000 plus lines even reaching 40,000 lines or more. The code below will get all the text from an active Notepad++ window but fails if the string content is huge.
public unsafe string GetText(int length)
{
	 byte[] textBuffer = new byte[10000];
	 fixed (byte* textPtr = textBuffer)
	 {
		Win32.SendMessage(scintilla, SciMsg.SCI_GETTEXT, (IntPtr)length, (IntPtr)textPtr);
		return Encoding.UTF8.GetString(textBuffer).TrimEnd('\0');
	 }
}
After doing some debugging and troubleshooting, I found a solution that is to replace the size of the textBuffer variable from a static value 10000 to the actual length passed into the function parameter.
public unsafe string GetText(int length)
{
	 byte[] textBuffer = new byte[length];
	 fixed (byte* textPtr = textBuffer)
	 {
		Win32.SendMessage(scintilla, SciMsg.SCI_GETTEXT, (IntPtr)length, (IntPtr)textPtr);
		return Encoding.UTF8.GetString(textBuffer).TrimEnd('\0');
	 }
}
Since the length is set using the ScintillaGateway GetLength() function.
length = scintillaGateway.GetLength();
supplementAllText = scintillaGateway.GetText(length + 1);
Output
Notepad++ Plugin GetText Method Not Getting Entire String In C#


Cheers!

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Bootstrap Modal In ASP.NET MVC With CRUD Operations