>>string x = "I'm a boy";
>>"I'm a boy"
>>x.Replace("'","\'")
>>"I'm a boy" && output - wrong
>
>See code below:
>
>string s = "I'm a man";
>MessageBox.Show(s, "before");
>s = s.Replace("'", @"\'");
>MessageBox.Show(s, "after");
>
>
>The '\' is the escape character in C languages and is a very special character. You can escape the escape character by adding another escape character (s = s.Replace("'", "\\'");) or by using the @ infront of the string.
I'm trying this in the immediate window. This code gives me double \\. I need a single \ because this is for the Javascript. Perhaps I need to continue reading google links I found on "JavaScript single quote escape".
If it's not broken, fix it until it is.
My Blog