Given the string “a|bc\de,fg~h,ijk,lm|no\p” what is the best way to add a ‘\’ before the ‘|’ ‘,’ ‘~’ and ‘\’
So the end string would be “a\|bc\de\,fg\~h\,ijk\,lm\|no\p”
What is the best way to do this?
I need this in c#.
Then i also need a way to get this string in JavaScript and remove all extra backslashes.
Thank you in advance.
EDIT
Can any one help me the the javacsript function that will give me back the original string, take off the extra \?
Regex would be overkill. Use String.Replace Method (String, String):
This produces
"a\|bc\\de\,fg\~h\,ijk\,lm\|no\\p"There’s probably more than one way to get the string out for JavaScript. It will depend on where you’re generating the string. For illustration purposes, say you’re generating the string in the code behind and putting it in some control (like a hidden field, perhaps) on the client.
In the client you would get the string and use the Javascript String.Replace method, something like this, assuming str1 is
"a\|bc\\de\,fg\~h\,ijk\,lm\|no\\p":It’s been a while since I’ve done JavaScript, so you may need to escape the backslash with another backslash (like
\\).