Well, i really don't know, maybe the title would be in appropriate.

Here's my problem:

Textbox1.text =

abcd
sadsadasdas
dsad
as
das
d
1234

After parsing between abc and 1234
It shows sadsadasdasdsadasdasd

However it should also contain spaces.
Here's my piece of code:

Dim daniweb As String = TextBox1.Text


        Dim indexdaniwebstart As Integer = daniweb.IndexOf("abcd") + 4 '

        Dim indexdaniwebend As Integer = daniweb.IndexOf("1234")


        Dim danisoft As Integer = indexdaniwebend - indexdaniwebstart


        daniweb = daniweb.Substring(indexdaniwebstart, danisoft)

        Dim dani() As String = daniweb.Split(vbNewLine.ToCharArray)

        For Each line As String In dani 
            If Not line.StartsWith(" ") Then 
                If TextBox2.Lines.Length = 0 Then
                    TextBox2.Text &= line  
                Else
                    TextBox2.Text &= line
                End If
            End If
        Next

Shows something like this:

It should display it like this:

sadsadasdas
dsad
as
das
d

Thanks

Dani AI

Generated

The concatenation you see comes from rebuilding the output without re-inserting the original line breaks. was on the right track pointing at the missing separator; a more robust fix is to extract the block between markers and then let the textbox display the preserved lines (or re-join them with the platform newline) instead of appending each line manually.

Example (keeps the original line breaks and handles multi-line extraction):

Imports System.Text.RegularExpressions

Dim input As String = TextBox1.Text
Dim startMark As String = "abcd"
Dim endMark As String = "1234"

Dim pattern As String = Regex.Escape(startMark) & "(.*?)" & Regex.Escape(endMark)
Dim m As Match = Regex.Match(input, pattern, RegexOptions.Singleline)

If m.Success Then
    Dim body As String = m.Groups(1).Value.Trim(vbCrLf)
    ' Normalize different newline styles and assign the Lines array so the control renders them correctly
    body = Regex.Replace(body, "\r?\n", Environment.NewLine)
    TextBox2.Lines = body.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
End If

Quick notes and checks:

  • RegexOptions.Singleline lets the capture span multiple lines; Regex.Escape avoids marker collisions.
  • Assigning TextBox2.Lines (or TextBox2.Text = body) preserves visible line breaks instead of concatenating lines.
  • If the input might use just LF or CRLF, normalize with Regex.Replace(body, "\r?\n", Environment.NewLine).
  • Guard against missing markers (check m.Success) and avoid splitting on single CR/LF characters which can drop separators unintentionally.
  • If you only want to drop lines that start with whitespace, use If Not String.IsNullOrWhiteSpace(line) Then or line.TrimStart() rather than testing StartsWith(" ").

This approach is clearer, faster, and avoids manual concatenation bugs.

I'm confused with what you are expecting to see. Do you want the two textboxes to look the same without the first and last line or do you want it in a single line with a space between each value like this...

sadsadasdas dsad as das d

Either way, I think your problem is that lines 19 and 21 are identical. I'm guessing line 21 should include a vbnewline or a space.

TextBox2.Text &= vbnewline & line

or

TextBox2.Text &= " " & line

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.