Results 1 to 5 of 5

Thread: Remove Line Break

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Uk
    Posts
    157

    Remove Line Break

    Hi, can anyone tell me how to remove the extra line break when using this code:

    Code:
            Dim str As String = SerialTextBox.Text.Replace(" ", vbCrLf).Replace(vbTab, vbCrLf)
            For Each s As String In str
                Dim query As String = "INSERT INTO SerialNumbers (Serial) VALUES ('" & s & "')"
                Dim adapter As New OleDbDataAdapter(query, con1)
                Dim dt As New DataTable("SerialNumbers")
                adapter.Fill(dt)
                adapter.Update(dt)
                con1.Close()
            Next
    If i put the following in a textbox:

    1
    2
    3

    it gets input into the database as

    1

    2

    3

    instead of

    1
    2
    3

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Remove Line Break

    For Each s As String In str

    This gives you every character in the string as a separate value. There is no extra carriage return, it's just that you are creating a separate record for each character. For 11,12,13 therefore you would get ..

    1
    1

    1
    2

    1
    3
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Uk
    Posts
    157

    Re: Remove Line Break

    oh so it does, how would i select each line instead of each character?

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Remove Line Break

    Dim lines = str.Split({vbCrLf}, StringSplitOptions.RemoveEmptyEntries)
    For Each s In lines
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Uk
    Posts
    157

    Re: Remove Line Break

    That seems to join the 2 lines instead of splitting them

    Code:
            Dim str As String = SerialTextBox.Text.Replace(" ", vbCrLf).Replace(vbTab, vbCrLf)
            Dim lines = str.Split({vbCrLf}, StringSplitOptions.RemoveEmptyEntries)
            For Each s In lines
                Dim query As String = "INSERT INTO SerialNumbers (Serial) VALUES ('" & s & "')"
                Dim adapter As New OleDbDataAdapter(query, con1)
                Dim dt As New DataTable("SerialNumbers")
                adapter.Fill(dt)
                adapter.Update(dt)
                con1.Close()
            Next
    Red
    Blue

    is input into the database as

    RedBlue

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width