Say I have an array of strings, like this:
var folders = new[] { "Foo", "Bar", "Foo\Bar" "Foo\Bar\Baz" }; And that I have an object that represents a folder - something like this:
class Folder { private readonly string _name; private readonly IEnumerable<Folder> _folders; public Folder(string name, IEnumerable<Folder> folders) { _name = name; _folders = folders; } public string Name { get { return _name; } } public IEnumerable<Folder> Folders { get { return _folders; } } } What would be a good way to end up with an object structure like this?
- Folder {Name:Foo} - Folder {Name:Bar} - Folder {Name:Baz} - Folder {Name:Bar} I'm thinking this in terms of splitting the strings on the delimiter and then grouping... and I'm thinking this wrong, I simply don't have an approach to get there, it's not going anywhere. I get the gut-feeling that I need to involve recursion somehow, but I don't see where to fit that in, I'm stuck.
The example code above is C#, but I don't need actual code, just some pseudo-code, or a line of thought, a little clue.
...I hope it's in-scope?