Search code examples
c#stringdictionarydecodeencode

Dictionary from a string skips new line character


EDIT

(C#) I have an dictionary coded as string and I want to retrieve it back. The problem is that, I use regex and I get dictionary without '\n' key.

Here is code preview for console application: dictionaries example

If you can see, the first and second dictionaries doesn't match. Sorry guys for bad question format.


Solution

  • Because your question isn't clear enough. I will have to make some assumptions here. Try adding RegexOptions.Singleline option to your Regex.

    var dictionary = Regex.Matches(frequencies, @".\d+.", RegexOptions.Singleline).Cast<Match>().ToDictionary(x => Convert.ToByte(x.Value[0]), x => int.Parse(x.Value.Substring(1, x.Value.Length - 2)));
    

    Test Online