C#字符串拆分优雅解决方案
本文关键字:解决方案 拆分 字符串 | 更新日期: 2023-09-27 18:25:28
寻求将属性和值提取到任何方便的数据结构中的建议和优雅的解决方案。
Text="{Binding Path=SelectedValue,Mode=TwoWay}"
解决方案是拥有某种东西:
List<string1, string2> where string1=Path, string2=SelectedValue
编辑:
有没有可能使其通用化,同时理解当前的一种方式和:
Command="{Binding ExecuteSearchCommand}
使用:
var result = Regex.Matches(input, @"('w+)=('w+)").Cast<Match>()
.Select(m => new
{
Property = m.Groups[1].Value,
Value = m.Groups[2].Value
});
如果您可以选择稍微重新格式化字符串,使其符合JSON规范(即用:替换您的=,那么您可以使用以下技术之一):
使用JSON.net 解析JSON
在C#中解析JSON