how to remove the first line of textbox and add it to other textbox?
Printable View
how to remove the first line of textbox and add it to other textbox?
Code:TextBox2.Text = TextBox1.Lines(0) 'copied the first line
Dim b As String() = Split(TextBox1.Text, vbNewLine), splits the text into lines
TextBox1.Text = String.Join(vbNewLine, b, 1, b.Length - 2) ' joins them together again, ignoring the first line
First of all, everyone who posts a question here needs help, so your thread title is all but useless. The title is supposed to help us determine which threads are relevant to us without having to waste our time opening every single one. Sometimes, if the title doesn't tell me anything then I just ignore the thread. Do you want people ignoring your thread? Please provide a title that describes the topic of the thread.
As for the question, you should work with the Lines property of the TextBox, which allows you to get or set the contents of the control as a String array containing one element per line. You can get the Lines property and get the first line from the first element. You can then copy all but the first line to a new array, which can be done in several ways. One way would be to create a List(Of String) from the array, Remove the first item and then create a new array from the List. You can then assign the new array back to the Lines property. As for adding the line to another TextBox, you could use the AppendText method or just the concatenation operator (&), or you could work with the Lines property again.
vb.net Code:
Dim transfer As String = TextBox1.Lines(0) TextBox1.Text = TextBox1.Text.Substring(transfer.Length + 1) TextBox2.AppendText(vbCrLf & transfer) 'adds at end '------- OR ------- TextBox2.Text = transfer & vbCrLf & TextBox2.Text 'adds at start