• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

Using Regex.Escape

Hi,

I got these two lines of code:

        1. text = text.Replace("\", Regex.Escape("\"));
        2. text = text.Replace("'", "\'");

The first line give me a compiling error:
         error CS1010: Newline in constant

Rem out the first line.  Run w/ the debugger the second line did not work, it didnot replace ' with \'

Please advise.

Diane Ha

0
tnova1
Asked:
tnova1
  • 2
1 Solution
 
hongjunCommented:
2. should be

text = text.Replace("'", "\\'");
0
 
hongjunCommented:
1. should be

text = Regex.Replace(text, Regex.Escape("\\"));
0
 
tnova1Author Commented:
Hi hongjun

    The correct answer for the first line:
          text.Replace("\\", Regex.Escape("\\"));

     Your 2nd line is right.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now