Keys separate into groups.

the way this works it takes the duplicate keys and the first one it finds it keeps and eliminates the rest.
What I need to do is when key A2 is found take that group and do something with it until it finds the next group.
So if it finds A2 again I will be able to do something with that group and so fourth.
basically each group is separated.
 
const string data = "A2='Founndowment\r\nB9='-0.0377\r\nC11='4245497.16\r\nD16\r\nA2='Belvaderer\nB10='-0.0377\r\nC14='4245497.16\r\nD19\r\nA2='newrowtitler\r\nC43='4245497.16\r\nD44";


var sFileLinesss = output.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(pairs => pairs.Split('=')).GroupBy(pair => pair[0], pair => pair.Count() == 2 ? pair[1] : string.Empty).ToDictionary(k => k.Key, v => v.FirstOrDefault());
          foreach (var pair in sFileLiness)
				Console.WriteLine("Key: {0}; Value: {1}", pair.Key, pair.Value);
			Console.ReadLine();

Open in new window

LVL 9
Seven priceFull StackAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
What is your question?
0
Seven priceFull StackAuthor Commented:
ok for example if A2 = Founndowment then use all values
if A2 = Belvaderer then get all values until it gets to the next key A2.
0
Seven priceFull StackAuthor Commented:
example 
if key A2 = Founndowment then
get 
   key   value
A2 A2=  'Founndowment
   B9=  '-0.0377
   C11=  '4245497.16
   D16 = ''

if A2 = Belvaderer
   A2=  Belvaderer 
   B10= '-0.0377 
  C14=' 4245497.16
  D19 = ''

if A2 =newrowtitler
   A2 =newrowtitler
   C43='4245497.16
   D44 = ""

Open in new window

0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

it_saigeDeveloperCommented:
You already have the groups.  If you want to retain all values in the groups then simply set the value of the keyvaluepair to that of the value group instead of the first or default item; e.g. -
using System;
using System.Linq;

namespace EE_Q28839299
{
	class Program
	{
		const string data = "A2='Founndowment\r\nB9='-0.0377\r\nC11='4245497.16\r\nD16\r\nA2='Belvaderer\nB10='-0.0377\r\nC14='4245497.16\r\nD19\r\nA2='newrowtitler\r\nC43='4245497.16\r\nD44";

		static void Main(string[] args)
		{
			var sFileLinesss = data.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(pairs => pairs.Split('=')).GroupBy(pair => pair[0], pair => pair.Count() == 2 ? pair[1] : string.Empty).ToDictionary(k => k.Key, v => v.ToList());
			foreach (var pair in sFileLinesss)
			{
				Console.WriteLine("Key: {0}; Value Count: {1}", pair.Key, pair.Value.Count);
				foreach (var value in pair.Value)
				{
					Console.WriteLine("Value: {0}", value);
				}
				Console.WriteLine();
			}
			Console.ReadLine();
		}
	}
}

Open in new window

Which produces the following output -Capture.JPG-saige-
0
it_saigeDeveloperCommented:
Ah, nevermind.  I understand what you are asking now.

-saige-
1
it_saigeDeveloperCommented:
So you need something like a collation (think printer based collation, or pigeon-hole based selection).  With that in mind, let's make an extension method:
static class Extensions
{
	public static IEnumerable<IDictionary<T, T>> ToCollation<T>(this IEnumerable<IEnumerable<T>> source)
	{
		List<Dictionary<T, T>> results = new List<Dictionary<T, T>>();
		Dictionary<T, T> current = new Dictionary<T, T>();
		foreach (var pair in source)
		{
			T[] array = pair.ToArray();
			if (current.ContainsKey(array[0]))
			{
				results.Add(current);
				current = new Dictionary<T, T>();
			}
			current.Add(array[0], array.Count() == 2 ? array[1] : default(T));
		}

		if (current.Keys.Count() != 0)
			results.Add(current);

		return results;
	}
}

Open in new window


Example usage -
using System;
using System.Collections.Generic;
using System.Linq;

namespace EE_Q28839299
{
	class Program
	{
		const string data = "A2='Founndowment\r\nB9='-0.0377\r\nC11='4245497.16\r\nD16\r\nA2='Belvaderer\nB10='-0.0377\r\nC14='4245497.16\r\nD19\r\nA2='newrowtitler\r\nC43='4245497.16\r\nD44";

		static void Main(string[] args)
		{
			var sFileLinesss = data.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(pairs => pairs.Split('=')).ToCollation();
			foreach (var dictionary in sFileLinesss)
			{
				foreach(var pair in dictionary)
				{
					Console.WriteLine("Key: {0}; Value: {1}", pair.Key, pair.Value);
				}
			}
			Console.ReadLine();
		}
	}

	static class Extensions
	{
		public static IEnumerable<IDictionary<T, T>> ToCollation<T>(this IEnumerable<IEnumerable<T>> source)
		{
			List<Dictionary<T, T>> results = new List<Dictionary<T, T>>();
			Dictionary<T, T> current = new Dictionary<T, T>();
			foreach (var pair in source)
			{
				T[] array = pair.ToArray();
				if (current.ContainsKey(array[0]))
				{
					results.Add(current);
					current = new Dictionary<T, T>();
				}
				current.Add(array[0], array.Count() == 2 ? array[1] : default(T));
			}

			if (current.Keys.Count() != 0)
				results.Add(current);

			return results;
		}
	}
}

Open in new window

Which produces the following output -Capture.JPGGranted there are most likely other ways to do this (and probably a linq-based way that I can't put my finger on [haven't finished my morning coffee]).

-saige-
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Seven priceFull StackAuthor Commented:
LOL well thanks for this. if you have another way please do not hesitate to share. Love to follow you to see what else you come up with. Great Thank you.
0
Seven priceFull StackAuthor Commented:
saige  one last thing
How can add I rownumbers for each group

   if (sFileLinesss[0])

   if (sFileLinesss[1])q
0
it_saigeDeveloperCommented:
What constitutes a rownumber? (the count of elements; keys, the total values or the total values for a key)

-saige-
0
Seven priceFull StackAuthor Commented:
Yes
0
it_saigeDeveloperCommented:
Which one of the three?

-saige-
0
Seven priceFull StackAuthor Commented:
this constitutes a rownumber for each group. Then within each group you have the key and value.
0
it_saigeDeveloperCommented:
So if I understand you correctly, you want something like:
using System;
using System.Collections.Generic;
using System.Linq;

namespace EE_Q28839299
{
	class Program
	{
		const string data = "A2='Founndowment\r\nB9='-0.0377\r\nC11='4245497.16\r\nD16\r\nA2='Belvaderer\nB10='-0.0377\r\nC14='4245497.16\r\nD19\r\nA2='newrowtitler\r\nC43='4245497.16\r\nD44";

		static void Main(string[] args)
		{
			var sFileLinesss = data.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(pairs => pairs.Split('=')).ToCollation();
			foreach (var group in sFileLinesss)
			{
				foreach (var pair in group.Value)
				{
					Console.WriteLine("RowNumber: {0}; Key: {0}; Value: {1}", group.Key, pair.Key, pair.Value);
				}

			}
			Console.ReadLine();
		}
	}

	static class Extensions
	{
		public static Dictionary<int, Dictionary<string, string>> ToCollation(this IEnumerable<IEnumerable<string>> source)
		{
			var results = new Dictionary<int, Dictionary<string, string>>();
			var current = new Dictionary<string, string>();
			var index = 0;
			foreach (var pair in source)
			{
				var array = pair.ToArray();
				if (current.ContainsKey(array[0]))
				{
					results.Add(index, current);
					current = new Dictionary<string, string>();
					index++;
				}
				current.Add(array[0], array.Count() == 2 ? array[1] : default(string));
			}

			if (current.Keys.Count() != 0)
				results.Add(index, current);

			return results;
		}
	}
}

Open in new window

Which produces the following output -Capture.JPG-saige-
0
it_saigeDeveloperCommented:
That being said, we could get the same results by changing the IEnumerable return to a list and using the IndexOf method to look up the index of each dictionary; e.g. -
using System;
using System.Collections.Generic;
using System.Linq;

namespace EE_Q28839299
{
	class Program
	{
		const string data = "A2='Founndowment\r\nB9='-0.0377\r\nC11='4245497.16\r\nD16\r\nA2='Belvaderer\nB10='-0.0377\r\nC14='4245497.16\r\nD19\r\nA2='newrowtitler\r\nC43='4245497.16\r\nD44";

		static void Main(string[] args)
		{
			var sFileLinesss = data.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(pairs => pairs.Split('=')).ToCollation();
			foreach (var dictionary in sFileLinesss)
			{
				foreach(var pair in dictionary)
				{
					Console.WriteLine("RowNumber: {0}; Key: {1}; Value: {2}", sFileLinesss.IndexOf(dictionary), pair.Key, pair.Value);
				}
			}
			Console.ReadLine();
		}
	}

	static class Extensions
	{
		public static List<Dictionary<string, string>> ToCollation(this IEnumerable<IEnumerable<string>> source)
		{
			List<Dictionary<string, string>> results = new List<Dictionary<string, string>>();
			Dictionary<string, string> current = new Dictionary<string, string>();
			foreach (var pair in source)
			{
				string[] array = pair.ToArray();
				if (current.ContainsKey(array[0]))
				{
					results.Add(current);
					current = new Dictionary<string, string>();
				}
				current.Add(array[0], array.Count() == 2 ? array[1] : default(string));
			}

			if (current.Keys.Count() != 0)
				results.Add(current);

			return results;
		}
	}
}

Open in new window

Which produces the same output as above.

-saige-
0
Seven priceFull StackAuthor Commented:
got it worked. Hope your weekend you are truly blessed. thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.