Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Replacing \ with / using String.Replace in C#

The following code will be helpful to replace the special characters.
Remember to use '@' operator to allow C# to recognize them.

  1. using System;
  2. using System.IO;
  3.  
  4. public class ForgetCode
  5. {
  6. public static void Main()
  7. {
  8. string str = @"C:\home\level\one";
  9. string newstr = str.Replace(@"\","/");
  10.  
  11. Console.WriteLine("Input: "+str);
  12. Console.WriteLine("Output: "+newstr);
  13. }
  14. }

Output:
Input: C:\home\level\one
Output: C:/home/level/one