|
-
Apr 30th, 2013, 01:12 PM
#1
Thread Starter
Addicted Member
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
-
Apr 30th, 2013, 01:36 PM
#2
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!
-
Apr 30th, 2013, 02:06 PM
#3
Thread Starter
Addicted Member
Re: Remove Line Break
oh so it does, how would i select each line instead of each character?
-
Apr 30th, 2013, 02:26 PM
#4
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!
-
Apr 30th, 2013, 02:34 PM
#5
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|