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
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