I have several keys (which represents subjects) in a dictionary and with that I associate several values(codes) per key.
CODE SUBJECT
7DIM-039 Communication
7DIM-040 Communication
7DIM-041 Communication
7DIM-042 Communication
7DIM-043 Communication
in order to associate eache subject(key) with the several values(code) i do this in my query. I created a dictionary
Dictionary<string, List<string>> dict = new Dictionary<string,List<string>>();
while (dbReader.Read())
{
string code = (string)dbReader["CODE"];
string subject = (string)dbReader["SUBJECT"];
if (!dict.ContainsKey(subject))
{
dict.Add(subject, new List<string> { code });
}
else
{
dict[subject].Add(code);
}
}
so this is the result
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.
example:
GenSubject;Careers; Listening Skills; Personal Development; Questioning Skills; Coaching/Mentoring etc.
How can I split these values and still make sure that the various code values are associated to each split value?
foreach(var kvp in dict)
{
foreach (var s in kvp.Key)
{
//splitting the subject keys?
}
}
I have also deviced a split method
static string[] SplitStringAt(string splitItem, char character)
{
return splitItem.Split(character);
}
This is an example
CODE GenSubject
7DIM-062 Communication, Questioning Skills, Decision-making
7DIM-063 Communication, Questioning Skills, Decision-making
7DIM-064 Communication, Questioning Skills, Decision-making
7DIM-065 Communication, Questioning Skills, Decision-making
7DIM-066 Communication, Questioning Skills, Decision-making
7DIM-067 Communication, Questioning Skills, Decision-making
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.