-1

I am currently working on a project and I need to delete the first line of a TextBox. How can I delete this first line? It is supposed to delete the line at every loop. I am using a WindowsFormApp in Visual Studio.

  • 1
    What sort of TextBox? Please tag `WPF`, `WinForms`, `ASP.NET`, etc. to indicate the technology you are working with. – John Wu Oct 11 '18 at 00:35
  • Can you post your code for this? – Ben Oct 11 '18 at 00:35
  • If you want to delete 1 line, why do you need a loop? Perhaps some code would help us understand. Certainly [Ask] and the WELCOME [TOUR] would help you understand the site better – Ňɏssa Pøngjǣrdenlarp Oct 11 '18 at 00:35
  • could you post your text also? – Arphile Oct 11 '18 at 00:36
  • Mr.Cofee already answered my question ahah – Alexis Oster Oct 11 '18 at 02:53
  • The way this place works is that if someone helped you or you feel that their answer was good, you upvote them. If you asked a question, and you ended up using one of the answers, you "accept" it. That way 2 things happen 1) the answerer gets a _"reputation"_ boost, but more importantly, the next person who asks a question like yours gets an indication of which answers were good and answered the question – Flydog57 Oct 12 '18 at 03:27
  • The reason why I don't put any lines of code is because I speak french and my lines are in french – Alexis Oster Oct 15 '18 at 00:04

3 Answers3

0

You could try this:

ctrl.Text = @"First
                2nd
                3rd";

var lines = multiline.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
ctrl.Text = string.Join(Environment.NewLine, lines.Skip(1));

For more details on how to split the text into lines please see Best way to split string into lines .

tymtam
  • 31,798
  • 8
  • 86
  • 126
0
richTextBox1.Lines = richTextBox1.Lines.Skip(1).ToArray();
mr.coffee
  • 962
  • 8
  • 22
0

For a plain old Windows Forms multiline text box, this works:

 var wasText = textBox1.Text;
 var lineEndIndex = textBox1.Text.IndexOf(Environment.NewLine);
 if (lineEndIndex >= 0) {
     textBox1.Text = wasText.Substring(lineEndIndex + Environment.NewLine.Length);
 }
Flydog57
  • 6,851
  • 2
  • 17
  • 18