We have currently started to evaluate AvalonEdit. We want to use it for a custom language. One of our requirements is to reorder and also to sort document lines by a certain criteria. How can this be accomplished?
Thanks in advance!
We have currently started to evaluate AvalonEdit. We want to use it for a custom language. One of our requirements is to reorder and also to sort document lines by a certain criteria. How can this be accomplished?
Thanks in advance!
AvalonEdit provides the ICSharpCode.AvalonEdit.Document.DocumentLine
class but this class just provides meta data on the line's length, starting and ending offset and so on.
In my opinion, there are 2 ways to accomplish your problem
Loop through all lines using TextEditor.LineCount
and save the Line into a DocumentLine
using TextEditor.Document.GetLineByNumber(int number)
. Furthermore you can use TextEditor.Document.GetText(DocumentLine.Offset, DocumentLine.Length
to get the line's text
Use TextEditor.Text.Split('\n')
to get all lines as a string array.
I'd recommend you using the DocumentLine method. Even if you have to use the GetText method in order to get the line's text the meta data on the lines is very nice.
To get all DocumentLines you can use a loop
List<DocumentLine> DocumentLines = new List<DocumentLine>(TextEditor.LineCount - 1);
for (int i = 1; i < TextEditor.LineCount; i++)
{
DocumentLines.Add(TextEditor.Document.GetLineByNumber(i));
}