Question Compare 2 strings

anthony.yaghi

New member
Joined
Dec 10, 2013
Messages
2
Programming Experience
Beginner
Hello guys, this is my first post in here and unfortunately I am already asking question instead of helping :p

Here is the thing, I am coding an application that will need to check 2 lists of file names, lets say list1 and list2, than return the missing files in list2.

It should be pretty easy but I am having a problem, after splitting the the lists in 2 String arrays
list1--->updates()
list2--->installs()

Here is the problem, I am using this code to compare each string in updates to all strings in installs to see if any 2 matches (uplist is a textbox) :

VB.NET:
For i As Integer = 0 To (updates.Length - 1)
                For j As Integer = 0 To (installs.Length - 1)
                    If (Strings.Equals(updates(i), installs(j))) = False Then
                        uplist.Text += updates(i) + " not equals " + installs(j) + vbNewLine
                    Else
                        uplist.Text += updates(i) + " = " + installs(j) + vbNewLine
                    End If
                Next
            Next
the strings in updates are: doc1.docx LabBio.msi projection.pptx tex.txt
the strings in installs are: tex.txt

And here is what I am getting :

VB.NET:
doc1.docx not equals tex.txt
LabBio.msi not equals tex.txt
projection.pptx not equals tex.txt
tex.txt not equals tex.txt
You can see that it gives me "tex.txt not equals tex.txt", so I guess I am not using the String.Equals() the right way, I tried comparing them with "=" or "<>" but noting works.

Can anyone help figure out the problem ?
 
Firstly, your code says Strings.Equals and there's no such thing, so that can't actually be the code you're running.

Unless you want a case-insensitive comparison, the proper way to compare Strings is with the = operator. If that's not doing what you expect then it's because the Strings you're comparing don't contain what you think they do. Obviously "tex.txt" is equal to "tex.txt" so at least one of your Strings does not contain that text, i.e. there must be a space or some other character in there.
 
Back
Top