• 0

Regular Expression Question


Question

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

  • 0
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

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.