我有这个数据集:

  • BW\Website Implementation\Phase1\Backlog
  • BW\Website Implementation\Phase1\Iteration 0
    List<string> IterationPaths = new List<string>();
    foreach (WorkItem item in collection)
    {
      List<string> itpath = item.IterationPath.Split('\\').ToList<string>();
      itpath = itpath.Except(IterationPaths).ToList();
      foreach (string path in itpath)
      {
        IterationPaths.Add(path);
      }
    }
    

  • 但目前这给了我:
  • BW
  • 网站实现
  • Phase1
  • 待办事项
  • 迭代 0

  • 我需要它有:
  • BW
  • BW\网站实现
  • BW\Website Implementation\Phase1
  • BW\Website Implementation\Phase1\Backlog
  • BW\Website Implementation\Phase1\Iteration 0

  • 我需要做哪些调整才能使其发挥作用?

    最佳答案

    var itpath = item.IterationPath.Split('\\');
    
    int i = 1;
    var result = itpath.Select(x => string.Join("\\", itpath.Take(i++))).ToList();
    

    关于C# 字符串拆分路径以获取每个子路径,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24559262/

    10-11 17:11