Click here to Skip to main content
15,171,303 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
VB
Public Class Form1
    Dim readlinevalue As String = ""
    Dim readlinevalue2 As String = ""
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim i As Integer = 1
        For Each ReadlineValue As String In Me.TextBox1.Text.Split(Environment.NewLine)
            Console.WriteLine("firstloop")
            For Each ReadlineValue2 As String In Me.TextBox1.Text.Split(Environment.NewLine)
                Console.WriteLine("secondloop")
                Do Until i = 100
                    Console.WriteLine("Do_loop 100")
                    TextBox1.Lines = Array.FindAll(TextBox1.Lines, Function(line) Not line.Contains(ReadlineValue))

                    i = i + 1
                Loop
                i = 1
            Next
            TextBox1.Text += ReadlineValue + Environment.NewLine
            If readlinevalue2.Contains(ReadlineValue) = False Then
                Console.WriteLine("true")
                TextBox2.Text += ReadlineValue + Environment.NewLine
            End If
        Next
    End Sub
End Class


What I have tried:

i have tried all most every thing
test this one
----------------------------------------
one
two
three
one
two
three
one
two
three
----------------------------------
Posted
Updated 2-Jun-16 4:56am
Comments
Member 10974007 2-Jun-16 9:48am
   
thanks you so much :)
it worked for me

1 solution

If you want to avoid using Linq for now then this works
VB
Dim tbLines = TextBox1.Text.Split(Environment.NewLine).ToList()
Dim tblNew = New List(Of String)
Dim sb = New StringBuilder("")

For Each s As String In tbLines
    If Not tblNew.Contains(s.Trim()) Then
        tblNew.Add(s.Trim())
        sb.Append(s.Trim())
        sb.Append(Environment.NewLine)
    End If
Next

'Remove the trailing NewLine
If sb.Length > Environment.NewLine.Length Then
    sb.Length -= Environment.NewLine.Length
End If

TextBox2.Text = sb.ToString()
Or ... a bit neater and using Linq
VB
Dim tbLines = TextBox1.Text.Split(Environment.NewLine).ToList()
Dim tblNew = New List(Of String)
Dim sb = New StringBuilder("")

For Each s As String In From s1 In tbLines Where Not tblNew.Contains(s1.Trim())
    tblNew.Add(s.Trim())
    sb.Append(s.Trim())
    sb.Append(Environment.NewLine)
Next

'Remove the trailine NewLine
If sb.Length > Environment.NewLine.Length Then
    sb.Length -= Environment.NewLine.Length
End If

TextBox2.Text = sb.ToString()

There is no need for two loops - I've used List(Of String) because I prefer lists to arrays and used the built in .Contains. If you want to keep it as an array then arrays also have a .Contains method.

I'm also using a StringBuilder to build up the new text rather than adding it directly to the new TextBox text. This is because strings are immutable, meaning they cannot be changed. Everytime you use
VB
TextBox1.Text += ReadlineValue + Environment.NewLine
you are actually getting a brand new string.

The only other thing to note is that I've trimmed the strings before adding them - this is because you have both "one" and " one" in your test data.
   
Comments
Member 10974007 3-Jun-16 22:36pm
   
IF I SAVE THE AFTER PROCESSING IN THIS I GET EXTRA NEWLINE CANT BE REMOVED IN EXCEL
CHill60 4-Jun-16 10:44am
   
Excel? This was about a multi-line textbox!
You'll have to share the code that you are using to save to excel.. and don't use all capitals - it's considered rude.
OriginalGriff 6-Jun-16 8:24am
   
Don't post comments as a solution - that doesn't let the person you are talking to know that you have a message for them.
Use the "Comment" or "Reply" system instead - that sends an email (like this one) to the appropriate person. I have moved your message.

And never post your email address in any forum, unless you really like spam! If anyone replies to you, you will receive an email to let you know.
OriginalGriff 6-Jun-16 8:22am
   
From a "solution" which I deleted:
relax we have a power problem in our area before its turn off we just dont think and wite..
and also found the solution for saving problem in excel....
i may need your little more help
my id is [DELETED]@gmail .com
am impressed with the short time you replied
thanks you so much..
CHill60 6-Jun-16 9:36am
   
Cheers. I have no idea what they meant (!) but thanks for passing it on
Member 10974007 7-Jun-16 22:35pm
   
http://www.codeproject.com/Questions/1105062/Contextmenustrip-for-evey-picturebox
can u answer this

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900