C# : How to get text from each line in RichTextBox

Advertisements

To get the text from each line in a RichTextBox in C#, you can use the `Lines` property of the RichTextBox control. This property returns an array of strings, where each string represents a line of text in the RichTextBox.

Here is an example of how you can use the `Lines` property to get the text from each line in a RichTextBox:

RichTextBox richTextBox = new RichTextBox();

// Populate the RichTextBox with some text
richTextBox.Text = "Line 1\nLine 2\nLine 3";

// Get the text from each line in the RichTextBox
string[] lines = richTextBox.Lines;

foreach (string line in lines)
{
    Console.WriteLine(line);
}

This will output the following text:

Line 1
Line 2
Line 3

You can then process the lines of text as needed in your code.

Leave a ReplyCancel reply