用于在路径列表中过滤顶级目录的算法,C#

时间:2013-06-23 22:33:23

标签: c# filter path directory

输入:

/dir1
/dir1/subdir
/dir1/subdir/sub-subdir
/dir2

输出应为:

/dir1
/dir2

2 个答案:

答案 0 :(得分:0)

这个怎么样:

string inputDir = "/dir1/subdir/sub-subdir";
string [] Split = inputDir.Split(new Char [] {'/'}, StringSplitOptions.RemoveEmptyEntries); 
string outputDir = Split[0];

答案 1 :(得分:0)

List<string> result= new List<string>();  

foreach (string i in input)
{
   string[] tmp = i.split(@"/");
   result.add(@"/" + tmp[0]);
}