How to retrieve the content of a line in AvalonEdit?

To retrieve the line content in AvalonEdit, you can use the following code:

using ICSharpCode.AvalonEdit.Document;

TextDocument document = textEditor.Document;
int lineNumber = 1; // 行号从1开始计数

// 获取指定行号的文本行
DocumentLine line = document.GetLineByNumber(lineNumber);
string lineText = document.GetText(line);

// 输出行内容
Console.WriteLine(lineText);

In the above code, we first obtain the TextDocument object of AvalonEdit, then retrieve the DocumentLine object of the specified line number using the GetLineByNumber method, and finally get the text content of that line using the GetText method.

bannerAds