02-25-2012, 09:55 AM
(02-24-2012, 01:12 PM)AceInfinity Wrote:(02-24-2012, 09:27 AM)★Cooldude★ Wrote:You shouldn't be using + though. The only reason that works is because VB explicitly defines the types on each side of the operand as a string for you, so it assumes that you want to concat them. Also, you should be putting the newline after the string, otherwise you'll end up with a new blank/empty line in the sorted textbox everytime. Also, I'm not sure why you're using the vb newline char or split though, there's already a method to get textbox lines.Code:For Each Str As String In TextBox1.Text.Split(vbNewLine)
If Str.Contains("@"c) Then
TextBox2.Text += vbNewLine & Str
End If
Next
Doing this is going to be very slow the more data you have in Textbox2:
Code:TextBox2.Text += vbNewLine & Str
Because what that does, is it looks at the whole value of Textbox2.Text, and then adds vbNewLine and Str to it, every time that loop goes through. You don't need to look at what's in Textbox2 every time, that should just be foregotten about, it should have taken care of itself if you're defining what data to add to it anyway, unless you need to double check it's value every time though, I don't see a reason to use &= or +=.
If there's lots of lines to iterate through too, stringbuilder is your best option as it's fast.
Code:Dim sb As New StringBuilder
For Each objLine As String In TextBox1.Lines
If objLine.Contains("@") Then
sb.AppendLine(objLine)
End If
Next
TextBox2.Text = sb.ToString
If you're sure that will do, otherwise you could use regex to find emails in each line... Or use something like this at least:
Code:If objLine.Contains("@"c) AndAlso objLine.Contains("."c) Then
I didn't realize you could get all of the lines in a textbox like that, thanks.