-
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
-
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
-
Re: Remove Line Break
oh so it does, how would i select each line instead of each character?
-
Re: Remove Line Break
Dim lines = str.Split({vbCrLf}, StringSplitOptions.RemoveEmptyEntries)
For Each s In lines
-
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