In order to debug an issue in my code, I have declared the following two strings, assuming they would be equivalent:
String print = "8A9B485ECDC56B6E0FD023D6994A57EEC49B0717";
String newPrint = thumbprint.Trim().Replace(" ", "").ToUpper();
I discovered they are not. Great, this is the source of my issue. However, I’m checking things in the immediate window (on the line following the declarations) and don’t understand what is happening. Here is the output:
print
"8A9B485ECDC56B6E0FD023D6994A57EEC49B0717"
newPrint
"8A9B485ECDC56B6E0FD023D6994A57EEC49B0717"
String.Compare(print, newPrint);
0
print == newPrint
false
print.Equals(newPrint)
false
huh? Why aren’t they equal?
edit:
I need to use ‘thumbprint’ as the base. It’s a user entered string. I’m just using ‘newPrint’ as a temporary variable to hold the trimmed/uppered value. print is the expected outcome.
Indeed, they are not equivalent. I copied the two values and
newPrinthas a length of 41 whereasprinthas a length of 40. The first character ofnewPrintis a character with the ASCII value 14. Interesstingly, this has been transfered from your immediate window to SO to my LINQPad.That actually has nothing to do with your
TrimandReplacecalls but with the fact that you are usingthumbprintinstead ofprintas the base. I can only assume thatthumbprintcontains that additional character. Where it comes from I don’t know. If you would change your second line to useprintinstead ofthumbprintyou would get the result you expect.