score:13

Accepted answer

Assuming that delimiters cannot appear in keys or values:

var dict = str.Split(';')
              .Select(s => s.Split(':'))
              .ToDictionary(a => a[0].Trim(), a => a[1].Trim()));

This is not the fastest way to do it, but it is the simplest.

You could also use a regex:

static readonly Regex parser = new Regex(@"([^:]):([^;])");

var dict = parser.GetMatches(str)
                 .Cast<Match>()
                 .ToDictionary(m => m.Groups[0].Value.Trim(), 
                               m => m.Groups[0].Value.Trim()
                 );

Related Query

More Query from same tag