C# Program to split parts in a Windows directory

CsharpProgrammingServer Side Programming

Firstly, set a string i.e. your Windows directory path −

string str = @"D:\Downloads\Amit";

Now use the Split() method and split wherever the \ occur −

str.Split(' \\')

The following is the complete code −

Example

 Live Demo

using System;
class Program {
   static void Main() {
      string str = @"D:\Downloads\Amit";
      Console.WriteLine("Directory...\n"+str);
      string[] myStr = str.Split('\\');
      Console.WriteLine("\nSplit...");
      foreach (string ch in myStr) {
         Console.WriteLine(ch);
      }
   }
}

Output

Directory...
D:\Downloads\Amit

Split...
D:
Downloads
Amit
raja
Published on 05-Sep-2018 12:17:51
Advertisements