सबसे पहले, एक स्ट्रिंग सेट करें यानी आपका विंडोज निर्देशिका पथ -
string str = @"D:\Downloads\Amit";
अब स्प्लिट () विधि का उपयोग करें और जहां भी \ घटित हो -
. को विभाजित करेंstr.Split(' \\') निम्नलिखित पूरा कोड है -
उदाहरण
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);
}
}
} आउटपुट
Directory... D:\Downloads\Amit Split... D: Downloads Amit