How to escape backslash (\) in a string using C#

1 Answer

0 votes
using System;
using System.Text.RegularExpressions;

namespace ConsoleApplication_C_Sharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            string s = @"\n\f5\";

            s = Regex.Escape(s);

            Console.WriteLine(s);
        }
    }
}


/*
run:
  
\\n\\f5\\
   
*/

 



answered Feb 7, 2017 by avibootz

Related questions

1 answer 278 views
1 answer 229 views
1 answer 210 views
210 views asked Oct 26, 2022 by avibootz
1 answer 246 views
1 answer 270 views
270 views asked Feb 7, 2017 by avibootz
1 answer 233 views
233 views asked Jun 6, 2021 by avibootz
...