Take the 2-minute tour ×



Output should be:

share|improve this question
Theres no algorithm, theres msdn documentation.. –  Sayse Jun 23 '13 at 22:35
"find the second / and stop there" –  Floris Jun 23 '13 at 22:36
add comment

2 Answers

up vote 0 down vote accepted

How about this:

string inputDir = "/dir1/subdir/sub-subdir";
string [] Split = inputDir.Split(new Char [] {'/'}, StringSplitOptions.RemoveEmptyEntries); 
string outputDir = Split[0];
share|improve this answer
Thanks ! actually we need Split[0] and Split[1], because the first occurrence is just the drive itself and if i needed just the root, there's already a filesysteminfo.root property for that. And that actually made this topic like a duplicate to this :) stackoverflow.com/questions/2599711/… –  Ilian Vasilev Kulishev Jun 23 '13 at 23:13
add comment

foreach (string i in input)
   string[] tmp = i.split(@"/");
   result.add(@"/" + tmp[0]);
share|improve this answer
add comment

Your Answer


