I have a massive string (we are talking 1696108 characters in length) which I have read very quickly from a text file. When I add it to my textbox (C#), it takes ages to do. A program like Notepad++ (unmanaged code, I know) can do it almost instantly although Notepad takes a long time also. How can I efficiently add this huge string and how does something like Notepad++ do it so quickly?
If this is Windows Forms I would suggest trying RichTextBox as a drop-in replacement for your TextBox. In the past I've found it to be much more efficient at handling large text. Also when making modifications in-place be sure to use the time-tested SelectionStart/SelectedText method instead of manipulating the Text property.
rtb.SelectionStart = rtb.TextLength;
rtb.SelectedText = "inserted text"; // faster
rtb.Text += "inserted text"; // slower
Notepad and Window TextBox class is optimized for 64K text. You should use RichTextBox
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With