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 273 views
1 answer 222 views
1 answer 204 views
204 views asked Oct 26, 2022 by avibootz
1 answer 242 views
1 answer 262 views
262 views asked Feb 7, 2017 by avibootz
1 answer 228 views
228 views asked Jun 6, 2021 by avibootz
...