I was programming a small notepad like app with some extra functionalities.
I am using a rich textbox as the main area. My question is while performing operations on the contents of the textbox, like code formatting, highlighting, etc which might require reading each character and replacing wherever necessary. Moving back across text indexes occasionally. What would be more efficient for an autoformat button:
Directly reading on the textbox.text property. Appending the formated string chars into a stringbuilder & finally back to the textbox (using toString function).
or
Copying the entire content into a string, reading character by character into a new stringbuilder.....and as above. Doesn't this method create an extra copy of the big text content in the textbox? Or is it more efficient than accessing the textbox control repeatedly?
Also if possible some ideas on keeping track of functions, brackets, braces, etc (for on-the-fly code formating) in the textbox code would be helpful.