输入:
/dir1
/dir1/subdir
/dir1/subdir/sub-subdir
/dir2
输出应为:
/dir1
/dir2
答案 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]);
}