Assuming that delimiters cannot appear in keys or values:
var dict = str.Split(';') .Select(s => s.Split(':')) .ToDictionary(a => a.Trim(), a => a.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.Value.Trim(), m => m.Groups.Value.Trim() );
- Create a dictionary<string,string> from a semicolon separated string using linq
- Object from comma separated string using linq
- Create a string collection from CheckedListBox.CheckedItems using LINQ
- Using Linq to return a Comma separated string
- Create a list of one object type from a list of another using Linq
- Using LINQ to parse the numbers from a string
- Create Items from 3 collections using Linq
- How to remove characters from a string using LINQ
- Split a separated string into hierarchy using c# and linq
- using LINQ how can i concatenate string properties from itesm in a collection
- convert comma separated string to list using linq
- Extract data from a XML string using linq vs xmlDocument
- Using LINQ to delete an element from a ObservableCollection Source
- How to create a comma delimited string from distinct list of values using LINQ?
- Access property in lambda expression from string when using LINQ
- Create List of Tuples from List using LINQ
- Using LINQ how do I create a List of one particular field of an entity from a collection entities
- Using LINQ to create pairs from two different list where the entries have same attribute
- Using LINQ to strip a suffix from a string if it contains a suffix in a list?
- I am trying create a new list of users from a list of users who have not created an additional object with a certain property using LINQ
- Make a List of String array from a List of String using LINQ
- Create Mapping from Dictionary of Lists using Linq
- How to Select the Token and Index from a Comma Separated String in Linq
- creating Linq to sqlite dbml from DbLinq source code
- Using LINQ lambda to replace characters from array in string
- Extract list of objects from a string using linq
- Select a matching string randomly from a list using LINQ
- LINQ to SQL create query from string
- To determine if one of the Strings from a list contains the initial part of a specified string using LINQ
- Using C# and Linq to create an array containing unique items from two input arrays
More Query from same tag
- Join 3 tables in .net core entity framework
- What are the best practicies for update list?
- How to export linq result to excel just like Linqpad
- linq query with list
- LINQ: Read an Excel file and then writing to database
- Select All columns for all tables in join + linq join
- If I create a List of XElements out of an XDocument, is a new copy of the element list created in memory?
- How to get ID that has a maximum value of Hits by grouping Date by in LINQ
- How to use LINQ to populate a object with a List<int> and a String?
- Printing out the results of my linq query
- Broken LINQ query with ternary expression
- Select all keys except some key
- LINQ, Lambda, C#, extension methods
- Searching for Singular and Plural of a word in Search Engine
- Merge Lists and return only duplicates
- How does linq Last() determine the last item?
- OrderByDescending not working properly in Linq
- A better way to find a difference between two arrays
- Populate class from an XML using Linq
- Return default value if Query is Empty
- Linq query for complicated model
- C# / LINQ - conditional LINQ query based on checkbox status
- Assigning LINQ Results to child Property - InvalidCastException: Unable to cast object of type
- Entity framework select with group by
- C# Nested object and concatenation
- How to make short lambda of multi join?
- MVC linq query and dropdown lists
- Sum and Group by in linq using Datarows
- Linq - Left Outer Join - DataTables
- How can I remove the time part from a nullable datetime in where condition of Linq