+chorpeac MVC Posted October 19, 2004 MVC Share Posted October 19, 2004 Ok I am trying to replace all the single quotes in a string with the escaped character single quote. Jessie's horse = Jessie\'s horse I tried to use String.Replace("'", "\'") but that didn't replace anything. Anyone know of a RegEx to do this? I'm not good enough with them to create them yet. Link to comment Share on other sites More sharing options...
0 justinclarke Posted October 19, 2004 Share Posted October 19, 2004 Ok I am trying to replace all the single quotes in a string with the escaped character single quote. Jessie's horse = Jessie\'s horse I tried to use String.Replace("'", "\'") but that didn't replace anything. Anyone know of a RegEx to do this? I'm not good enough with them to create them yet. 584766398[/snapback] I don't know C# so I don't know how it handles this exactly, but I'm thinking your problem is related to your replace string. Your replace string is \' which C# might just be interpreting as '. Try \\\' or as your replace string. The first \\\' might tell it: 1 backslash (\\) and one apostrophe (\'). If that doesn't work, just try \\' Hope this helps :) Link to comment Share on other sites More sharing options...
0 +chorpeac MVC Posted October 19, 2004 Author MVC Share Posted October 19, 2004 Ok I will give \\' a try Link to comment Share on other sites More sharing options...
0 +chorpeac MVC Posted October 19, 2004 Author MVC Share Posted October 19, 2004 Thanks JustinClarke, that was the correct step. \\' fixed the replace method. Link to comment Share on other sites More sharing options...
0 John Veteran Posted October 19, 2004 Veteran Share Posted October 19, 2004 Yeah, I was going to say you should be using String.Replace("\'", "\\\'") instead :p Link to comment Share on other sites More sharing options...
Question
+chorpeac MVC
Ok I am trying to replace all the single quotes in a string with the escaped character single quote.
Jessie's horse = Jessie\'s horse
I tried to use String.Replace("'", "\'") but that didn't replace anything.
Anyone know of a RegEx to do this? I'm not good enough with them to create them yet.
Link to comment
Share on other sites
4 answers to this question
Recommended Posts