Delete Lines From Beginning of Multiline Textbox in C#

c#, multiline, textbox

Solution

This is an incomplete question. So assuming you are using either TextBox or RichTextBox you can use the Lines property found inTextBoxBase.

//get all the lines out as an arry
string[] lines = this.textBox.Lines;

You can then work with this array and set it back.

  this.textBox.Lines= newLinesArray;

This might not be the most elegant way, but it will remove the first line. EDIT: you don't need select, just using skip will be fine

    //number of lines to remove from the beginning
    int numOfLines = 30; 
    var lines = this.textBox1.Lines;
    var newLines = lines.Skip(numOfLines);

    this.textBox1.Lines = newLines.ToArray();

Problem

Is there a graceful way in C# to delete multiple lines of text from the beginning of a multiline textbox? I am using Microsoft Visual C# 2008 Express Edition. EDIT - Additional Details The multiline textbox in my application is disabled (i.e. it is only editable by the application itself), and every line is terminated with a "\r\n".

Original source