views:

162

answers:

5

hi there,

this doesn't make any sense to me. must be wrong or painfully obvious.

after slicing and dicing, i got 2 vars with the following values in vb.net:

strTag = "&lt;#<span class=SpellE>vermittler_person_Name</span>&gt;"
tmp    = "&lt;#<span class=SpellE>vermittler_person_Name</span>&gt;"

comparing the vars gives a false:

strTag = tmp ' ==> false

comparing the values directly right there gives a true:

"&lt;#<span class=SpellE>vermittler_person_Name</span>&gt;" = "&lt;#<span class=SpellE>vermittler_person_Name</span>&gt;" ' ==> true

both are strings, i tried all kinds of stuff: string.compare, string.equals, also regex etc. etc. everything works perfect with all the other strings with simlilar structure, just not and only not with

"vermittler_person_Name"

in the middle... any ideas?

A: 
dim strTag as String 
dim tmp as String 

strTag = "&lt;#<span class=SpellE>vermittler_person_Name</span>&gt;"
tmp = "&lt;#<span class=SpellE>vermittler_person_Name</span>&gt;"

Console.WriteLine(strTag = tmp) 'prints True

Could you post the code, where it does the comparison?

EDIT: Before you do the comparison, print the content to the console to see if they differ

Console.WriteLine(strTag)
Console.WriteLine(tmp)
shahkalpesh
A: 

I cannot repro this problem. I tried the following code an VS2008 RTM and the value same is True

Sub Main()
    Dim strTag = "&lt;#<span class=SpellE>vermittler_person_Name</span>&gt;"
    Dim tmp = "&lt;#<span class=SpellE>vermittler_person_Name</span>&gt;"
    Dim same = strTag = tmp
    Stop
End Sub

Can you provide a runnable sample code of your problem? Including the Visual Studio version and options (Strict, Explicit, etc ...)

JaredPar
+8  A: 

I strongly suspect that although the two displayed strings were equal, the internal data wasn't equal. There could be any number of non-printing characters in there.

If you're able to reproduce this, I suggest you look at the Unicode value of each character of the offending strings. If I'm right, we won't be able to reproduce this via an SO post which only contains the visible characters, for obvious reasons.

Jon Skeet
wouldn't they show up in notepad++ or similar as non-printable chars? but anyway, great point! i'll try reproducable code and be right back. thanks!
handsomeGun
@handsomeGun: How would you copy them into notepad++ to start with? If it's from the debugger, that may well not have put them into the clipboard.
Jon Skeet
well, they usually get copied over as 'weird' chars. but you are spot on! the .length show a difference of 1. so I'll loop through the strings to spot the offending character. ( it didn't do that with many dozen others in the same method, that's why i was so startled..) thank you!
handsomeGun
+3  A: 

you can check the lengths of the two strings to see if they're the same, or convert both of them to the same case (upper or lower) to see if that's causing the difference

Beth
tried cases, will try length right now. thanks!
handsomeGun
yep, the .length is one off. damn. thank you!
handsomeGun
A: 

I do not have VB/.NET experience but this sounds similar to the behavior in java.

In java, you declare two string objects.

String a = new String("aa");
String b = new String("aa");

a.equals(b) will return true but a==b will return false.

Also "aa"=="aa" will return true.

This is because "aa" is a literal String (similar to a primitive) whereas a and b are two different objects that are distinct in memory.

VB/.NET behavior may be similar (I have no clue).

hashable