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 178 views
1 answer 140 views
1 answer 119 views
119 views asked Oct 26, 2022 by avibootz
1 answer 162 views
1 answer 165 views
165 views asked Feb 7, 2017 by avibootz
1 answer 150 views
150 views asked Jun 6, 2021 by avibootz
...