C#正则表达式获取html代码
html代码中有类似这样的内容nickName:'qq',userId:'123123',shopId:'456456',siteId:'11',siteCategory...
html代码中有类似这样的内容
nickName: 'qq',
userId: '123123',
shopId: '456456',
siteId: '11',
siteCategoryId: '22',
itemId: '',
shopStats: '',
validatorUrl: 'http://iu.duoduo.com/tgus.htm',
templateId: '56366',
请问用C#如何获得userId和shopId等的值。谢谢 展开
nickName: 'qq',
userId: '123123',
shopId: '456456',
siteId: '11',
siteCategoryId: '22',
itemId: '',
shopStats: '',
validatorUrl: 'http://iu.duoduo.com/tgus.htm',
templateId: '56366',
请问用C#如何获得userId和shopId等的值。谢谢 展开
2013-11-22
展开全部
string str = @"nickName: 'qq',
userId: '123123',
shopId: '456456',
siteId: '11',
siteCategoryId: '22',
itemId: '',
shopStats: '',
validatorUrl: 'http://iu.duoduo.com/tgus.htm',
templateId: '56366',";
str = str.Replace(" ", "");
MatchCollection mc = Regex.Matches(str,"[\\w]+:{1}'{1}.*'{1}");
Hashtable ht = new Hashtable();
string key, value;
foreach (Match m in mc)
{
key = Regex.Match(m.Value, "[\\w]+").Value;
value = Regex.Replace(m.Value, "[\\w]+:{1}", "");
value = value.Replace("'", "");
ht[key] = value;
}
userId: '123123',
shopId: '456456',
siteId: '11',
siteCategoryId: '22',
itemId: '',
shopStats: '',
validatorUrl: 'http://iu.duoduo.com/tgus.htm',
templateId: '56366',";
str = str.Replace(" ", "");
MatchCollection mc = Regex.Matches(str,"[\\w]+:{1}'{1}.*'{1}");
Hashtable ht = new Hashtable();
string key, value;
foreach (Match m in mc)
{
key = Regex.Match(m.Value, "[\\w]+").Value;
value = Regex.Replace(m.Value, "[\\w]+:{1}", "");
value = value.Replace("'", "");
ht[key] = value;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询