我应该如何构建分层文本数据? [英] How should I structure my hierarchical textual data?
问题描述
我正在创建一个分层文本数据列表,其格式如下所示。此数据将包含在纯文本文件中。我想把它读成某种结构(使用C#),我不确定哪种结构最好或C#中有什么可用。
第一行是标题行。
下一行是齐平左侧,是顶级项目。
与此顶级项目关联的项目显示在其下方,每条线条缩进一个空格。你可以看到模式。
在我的表单上,我将列出列表框中的顶级项目,当选择一个时,我想填充到右边的这个列表框是richTextBox组件中的关联项。
因此,我可以单击一个清单项,例如Before Start,并查看richTextBox中的相关项。 br />
我需要在这些数据中读取哪些选项并以某种数据结构存储?
谢谢......
I'm creating a hierarchical textual data listing with the format shown below. This data will be contained in a plain text file. I want to read it into some kind of structure (using C#) and I'm not sure what kind of structure would be best or what is available in C#.
The first line is the Title line.
The next line is flush left and is a Top Level item.
The items associated with this top level item are shown immediately below it, with each one of their lines indented by one space. You can see the pattern.
On my form, I will list the top level items in a listbox and when an is selected, I want to populate to the right of this listbox, the associated items in a richTextBox component.
So, I can click on a checklist item such as Before Start and see the associated items in the richTextBox.
What options do I have to read in this data and store in some kind of data structure?
Thanks...
Aircraft Type
Preflight
Oxygen
Navigation transfer and display switches
Window heat
Pressurization mode selector
Flight instruments
Before Start
Flight deck door
Fuel
Passenger signs
Windows
MCP
Before Taxi
Generators
Probe heat
Anti-ice
推荐答案
如果你坚持使用这种存储格式,那么你将不得不处理我你自己:
读取每一行,计算前导空格的数量,并确定它的去向。
你可能想要一个字典< ; string,List< string>>
其中键是顶级项目。
如建议的那样,XML文件会可能更容易使用,因为已有系统以分层方式提取数据。
If you insist on using this storage format, then you will have to handle it all yourself:
Read each line, count the number of leading spaces, and decide where it goes.
You'll probably want aDictionary<string, List<string>>
where the key is the top level item.
As has been suggested, an XML file would probably be a lot easier to use as there are already systems to extract the data in a hierarchical manner.
这篇关于我应该如何构建分层文本数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!