Note that there are some explanatory texts on larger screens.

plurals
  1. POSplitting the key values in a dictionary
    primarykey
    data
    text
    <p>I have several keys (which represents subjects) in a dictionary and with that I associate several values(codes) per key.</p> <p>CODE SUBJECT</p> <p>7DIM-039 Communication</p> <p>7DIM-040 Communication</p> <p>7DIM-041 Communication</p> <p>7DIM-042 Communication</p> <p>7DIM-043 Communication</p> <p>in order to associate eache subject(key) with the several values(code) i do this in my query. I created a dictionary </p> <pre><code>Dictionary&lt;string, List&lt;string&gt;&gt; dict = new Dictionary&lt;string,List&lt;string&gt;&gt;(); while (dbReader.Read()) { string code = (string)dbReader["CODE"]; string subject = (string)dbReader["SUBJECT"]; if (!dict.ContainsKey(subject)) { dict.Add(subject, new List&lt;string&gt; { code }); } else { dict[subject].Add(code); } } </code></pre> <p>so this is the result</p> <p><img src="https://i.stack.imgur.com/vOd25.png" alt="enter image description here"></p> <p>The problem I have is some of these keys are seperated by semi colons(so there are several items per key) so naturaly I have to do a split.</p> <p>example: GenSubject;Careers; Listening Skills; Personal Development; Questioning Skills; Coaching/Mentoring etc.</p> <p>How can I split these values and still make sure that the various code values are associated to each split value?</p> <pre><code>foreach(var kvp in dict) { foreach (var s in kvp.Key) { //splitting the subject keys? } } </code></pre> <p>I have also deviced a split method</p> <pre><code>static string[] SplitStringAt(string splitItem, char character) { return splitItem.Split(character); } </code></pre> <p>This is an example CODE GenSubject</p> <p>7DIM-062 Communication, Questioning Skills, Decision-making</p> <p>7DIM-063 Communication, Questioning Skills, Decision-making</p> <p>7DIM-064 Communication, Questioning Skills, Decision-making</p> <p>7DIM-065 Communication, Questioning Skills, Decision-making</p> <p>7DIM-066 Communication, Questioning Skills, Decision-making</p> <p>7DIM-067 Communication, Questioning Skills, Decision-making</p> <p>so what I want to achieve is all the codes to be 'stored for Comunication, and the the same codes for Questioning Skills etc. but of course only once.</p>
    singulars
    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.
 

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