How can I delete a specific line of text in a RichTextBox ?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
Here is my unit tested implementation.
Unit tests:
(used
\n
instead ofEnvironment.NewLine
since at least for me RTB is automatically replacing\r\n
with just\n
)Another solution:
I don't know if there is an easy way to do it in one step. You can use the .Split function on the .Text property of the rich text box to get an array of lines
and then write something to re-assemble the array into a single text string after removing the line you wanted and copy it back to the .Text property of the rich text box.
Here's a simple example:
If your rich text box was going to have more than 10 lines or so it would be a good idea to use a StringBuilder instead of a string to compose the new text with.