从文件夹位置列表创建对象层次结构
我有一个字符串形式的位置列表;
locA/locB
locA/locB/locH
locC/locD/locE
locC/locD/locE/locK
locF/locG
我一直在尝试创建一个对象,该对象使用与传递给它的位置列表相同的结构;
例如,类似......
var myHObject=CreateHeirarchicalObjectFromList(myStringListOfLocations);
我在循环遍历列表时遇到问题,而几乎没有手动执行大量循环。有没有更简单的方法,也许是递归?
我想最终得到一个像这样的物体;
.locA
.locB
.locH
.locC
.locD
.locE
.locK
.locF
.locG
我可以用它来创建视觉层次结构。
I have a list of locations as strings;
locA/locB
locA/locB/locH
locC/locD/locE
locC/locD/locE/locK
locF/locG
I've been trying to create an object that uses the same structure as the list of locations passed to it;
e.g. Something like..
var myHObject=CreateHeirarchicalObjectFromList(myStringListOfLocations);
I'm having problems looping through the list without almost doing it manually with loads of loops. Is there an easier way, maybe recursion?
I want to end up with an object like this;
.locA
.locB
.locH
.locC
.locD
.locE
.locK
.locF
.locG
That I can use to create a visual hierarchy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能不是最好的,但在 LinqPad 中被撞坏了,将在一秒钟内重新格式化..
Prob not the best but knocked up in LinqPad, will reformat in a sec..