C# String Splitting of a path to get every sub path
c#, linq, string
Solution
var itpath = item.IterationPath.Split('\\');
int i = 1;
var result = itpath.Select(x => string.Join("\\", itpath.Take(i++))).ToList();
Problem
I have this dataset: - 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); } } ``` But currently this is giving me: - BW - Website Implementation - Phase1 - Backlog - Iteration 0 I need it to have: - BW - BW\Website Implementation - BW\Website Implementation\Phase1 - BW\Website Implementation\Phase1\Backlog - BW\Website Implementation\Phase1\Iteration 0 What tweaks would I have to make for this to work?