我有简单的文字:
first_name=value1
secon_name=value2
date_b = 12.01.1989
行由\n
char分隔。我有代码分割这个字符串,然后我遍历数组并检查键:
string[] data = str.Split('\n');
foreach (var row in data)
{
if (row.StartsWith("first_name"))
{
obj.FirstName = row.Remove(0, ("first_name").Length);
...
}
}
但是大约有15对,foreach
中的代码非常难以理解。如何用正则表达式解析这个?我想获得dictionary<key, value>
。
PS。一些规则:
关键是没有空格
2.值可以包含空格。