Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To add to the other answers, if you don't want to parse the text file yourself, you could always use a quick and dirty regular expression if you're comfortable with them:</p> <pre><code>var regex = new Regex(@"Start Section \d+ - (?&lt;section&gt;\w+)\r\n(?&lt;list&gt;[\w\s]+)End Section", RegexOptions.IgnoreCase); var data = new Dictionary&lt;string, List&lt;string&gt;&gt;(); foreach (Match match in regex.Matches(File.ReadAllText("types.txt"))) { string section = match.Groups["section"].Value; string[] items = match.Groups["list"].Value.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); data.Add(section, new List&lt;string&gt;(items)); } // data["animals"] now contains a list of "dog", "cat", "horse", and "cow" </code></pre> <p>In response to the comment:</p> <blockquote> <p>but "list" sounds so simple and basic (like i am going shopping), array has much nicer ring to it ;) But I will look in to them maybe a bit more, I got the impression from my research that arrays are more efficent code?</p> </blockquote> <p>It's not about whether a list vs. array is "basic" or "has a nicer ring", it's about the purpose of the code. In your case, you're iterating a file line-by-line and adding items to a collection of an unknown size beforehand - which is one problem a list was designed to solve. Of course you could peek through the file and determine the exact size, but is doing that worth the extra "efficiency" you get from using an array, and is iterating the file twice going to take longer than using a list in the first place? You don't know unless you profile your code and conclude that specific portion is a bottleneck... which I'll say, will almost never be the case.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload