Swap multi line in VB

Asked by At

I have problem In swap multi line it only swap one line?

Dim st As String=TextBox1.Text
st=String.Join(":", st.Split(":"). Reverse())
TextBox1.Text =st



1 Answers

Mary On Best Solutions

You can use the Lines collection of the text box to operate on each line individually. I used a string builder to create the new text of the text box. When ever you change a string the compiler creates an entirely new string. A StringBuilder avoids some of this overhead.

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim sb As New StringBuilder
    For Each line As String In TextBox1.Lines
        sb.AppendLine(String.Join(":", line.Split(":"c).Reverse()))
    TextBox1.Text = sb.ToString
End Sub