Click here to Skip to main content
15,902,810 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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...

C#
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
Posted
Comments
George Jonsson 29-Jun-14 2:10am    
Why not use XML?
What you have created is basically an XML structure, but without the tags.

1 solution

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 a Dictionary<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.
 
Share this answer
 
Comments
rfresh 29-Jun-14 10:55am    
I will try both suggestions...thank you both...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900