Compare two strings in C# -
i store 2 serialized object in 2 text file , read both , store in 2 different string, , try compare 2 strings, comparison failed more 1 time because of carriage return , new line difference in end of 1 of string, how compare both ignoring spaces or carriage returns, know can compress 2 strings , compare them, there done .net library, icomparer, i'm not sure if work me too.
thank in advance jp
if both values stored strings, string.trim()
function take care of troublesome whitespace characters, or compare whilst replacing whitespace characters.
string = "string comparison\r\n"; string b = "string comparison"; string c = a.trim(); string d = b.trim(); if (c == d) console.writeline("strings equal"); else console.writeline("strings not equal"); string e = a.replace("\r\n", ""); string f = b.replace("\r\n", ""); if (e == f) console.writeline("strings equal"); else console.writeline("strings not equal");
Comments
Post a Comment