My program should process an input string. But when "\mesg" is sent in Method1, the else block is executed instead of the if block.
void Method()
{
string str = "\\Mesg";
str = Method1(str);
Console.WriteLine(str);
}
string Method1(string s)
{
string upadtedString = s;
if (s.Contains(@"\\"))
{
//do nothing
}
else if(s.Contains(@"\"))
{
upadtedString.Replace(@"\",@"\\");
s = upadtedString;
}
return s;
}
The best example is when "\0Mesg" is the input to Method1()
. This raises an XML serilaziation exception when I try to deserialze. Just to handle this I want to add another slash, "\0Mesg", before serialzing the string.
How can I make it work as expected?