|
-
July 12th, 2006, 09:20 AM
#1
[RESOLVED] String Comparison problem
I'm writing an application that will do a lot of string comparisons and noticed a little quirk.
A little background: The application reads data, serializes, then writes to an XML file. Later in time, the application will read in another set of data, serialize and store to an XML file. My application is to compare these two XML files, looking for changes. So, I deserialize into my class and do my comparison method. Everything works except when it hits the string:
"Logitech® Camera Driver"
Both classes contain this string but the code will never find them to be equal. Does something happen when this string gets serialized then deserialized to cause this comparison to return false? Might you guys know a work around?
-
July 12th, 2006, 09:25 AM
#2
Re: String Comparison problem
Maybe you should post your compare method and the serialize/deserialize block? 
I think you are running into charset problems during serialize/deserialize.
Useful or not? Rate my posting. Thanks.
-
July 12th, 2006, 09:36 AM
#3
Re: String Comparison problem
 Originally Posted by torrud
Maybe you should post your compare method and the serialize/deserialize block?
I think you are running into charset problems during serialize/deserialize.
The entire compare method is quite messy in this early stage but you can imagine that it looks at each element of the new deserialized class and searches for that same text in the old deserialized class. The actual comparison is something like:
Code:
if(XMLnewAtt.AttValue == XMLoldAtt.AttValue)
{
//We have a match!
}
What do you mean, exactly by serialize/deserialize block? I just use the XmlSerializer provided with .NET...
I'm betting there's something wrong with the deserialize method because the serialized XML files contain that string, exactly. As a side note, the data does get serialized with a special namespace.
-
July 12th, 2006, 12:15 PM
#4
Re: String Comparison problem
I wrote a small program to compare two strings containing "Logitech® Camera Driver" value. The double equal operator returns true. So, it is not the problem of == operator.
Now we narrow down the problem to the deserializer (since you say the value in serialized xml is correct). Run the debugger and check the value in XMLnewAtt.AttValue & XMLoldAtt.AttValue. As torrud suggested, it might be a problem with char.set (charactor encoding). For Xml serializer class, you need to provide a stream when you serialize and deserialze. Check how the stream is constructed in case of serialization and deserialization.
-
July 12th, 2006, 12:31 PM
#5
Re: String Comparison problem
Ok, I'll look into what you had said. I did check when the values actually get compared and it turns out that the new XML file, XMLnewAtt.AttValue, contained the string: "Logitech® Camera Driver" while the old XML file, XMLoldAtt.AttValue contained the string : "Logitech Camera Driver".
So something isn't correct in the deserialization. This confuses me as the same exact methods are used. I know the serialized streams are correct because they are written to file and those two values appear as "Logitech® Camera Driver". I will look at the stream as it gets deserialized and hopefully find something
-
July 12th, 2006, 12:49 PM
#6
Re: String Comparison problem
Got it guys. My old XML file did NOT contain this line:
Code:
<?xml version="1.0" encoding="utf-8"?>
which must've been causing the encoding issues you guys suggested. I added it and it works just fine now. It wasn't in there because the data gets sent to a SQL stored procedure. I hope I didn't waste anybodys time for to long
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
|