C# Program to split parts in a Windows directory
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...
"+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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP