- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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("
Split..."); foreach (string ch in myStr) { Console.WriteLine(ch); } } }
Output
Directory... D:\Downloads\Amit Split... D: Downloads Amit
Advertisements