简体   繁体   中英

C# string splitting elegant solution

Looking for advice and elegant solution extracting properties and values into any convenient data structure.

Text="{Binding Path=SelectedValue,Mode=TwoWay}"

Solution is to having something sort of:

 List<string1, string2> where string1=Path, string2=SelectedValue

EDIT:

is it possible to make it GENERIC, to understand both ways current one and:

Command="{Binding ExecuteSearchCommand}

Use:

var result = Regex.Matches(input, @"(\w+)=(\w+)").Cast<Match>()
    .Select(m => new 
        { 
            Property = m.Groups[1].Value, 
            Value = m.Groups[2].Value 
        });

If you have an option to reformat your string slightly so it matches the JSON spec (ie replace your = with :, then you could use one of the following techniques):

Parsing JSON using Json.net

Parse JSON in C#

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM