stringBuilder的问题。。。。。。。。
如何把stringBuilder里面的值赋给Dictionary
如stringBuilder的值为:{1:40000018331;2:40100000113;}
把1、2分别赋给Dictionary的key,
40000018331、40100000113 赋给Dictionary的value。
谢谢。
------解决方案--------------------var dict = sb.ToString().Split(';').Select(x => new { key = x.Split(':')[0], value = x.Split(':')[1] }).ToDictionary(x => x.key, x => x.value);
------解决方案--------------------
------解决方案--------------------
StringBuilder sb = new StringBuilder();
sb.Append("{1:40000018331;2:40100000113;}");
string str = sb.ToString().Replace("{","").Replace("}","");
string[] strs = str.Split(new char[]{';'}, StringSplitOptions.RemoveEmptyEntries);
Dictionary<string, string> dic = new Dictionary<string, string>();
string[] every;
for (int i = 0; i < strs.Length; i++)
{
every = strs[i].Split(':');
dic[every[0]] = every[1];
}
}
------解决方案--------------------