日期:2014-05-17 浏览次数:20468 次
isrequest:true,layer:2,id:0
public string GetValue(string args, string name) { string[] arr = args.Split(','); for (int i = 0; i < arr.Length; i++) { string[] arr2 = arr[i].Split(':'); if (arr2[0] == name) return arr2[1]; } return String.Empty; }
string s = "isrequest:true,layer:2,id:0"; string r = Regex.Match(s, @"isrequest:([^,]+)").Groups[1].Value; Response.Write(r);
------解决方案--------------------
string input=@"isrequest:true,layer:2,id:0";
MatchCollection mc=Regex.Matches(input,@"(?i)(\w+):(\w+)");
Dictionary<string,string> dic=new Dictionary<string,string>();
foreach(Match m in mc)
{
dic.Add(m.Groups[1].Value,m.Groups[1].Value);
}
/*
dic中的值
isrequest true
layer 2
id 0
*/
你也可以用split以,和;分隔
------解决方案--------------------
string s = "isrequest:true,layer:2,id:0";
string[] ss = s.Split(new char[] { ',', ':' });