积极答复者
C# 如何获取指定字符串中的值呢?

问题
答案
-
string str = "pageId=114776896;prototypeId=2;siteId=2;shopId=62112343;userid=444076877;";
string[] strs = str.Split(';');
string s = strs.Where(item => item.StartsWith("userid")).FirstOrDefault();
string result = s.Substring(s.IndexOf("=")+1, s.Length - s.IndexOf("=")-1);
Console.WriteLine(result);- 已建议为答案 CaillenModerator 2014年4月4日 9:40
- 已标记为答案 CaillenModerator 2014年4月11日 10:50
-
string s = "pageId=114776896;prototypeId=2;siteId=2; shopId=62112343; userid=444076877"; Regex reg = new Regex(@"userid=\d+"); Regex reg2 = new Regex(@"\d+"); Console.WriteLine(reg2.Match(reg.Match(s).Value).
ASP.NET Forum
Other Discussion Forums
FreeRice Donate
Issues to report
Free Tech Books Search and Download- 已标记为答案 CaillenModerator 2014年4月11日 10:50
全部回复
-
string str = "pageId=114776896;prototypeId=2;siteId=2;shopId=62112343;userid=444076877;";
string[] strs = str.Split(';');
string s = strs.Where(item => item.StartsWith("userid")).FirstOrDefault();
string result = s.Substring(s.IndexOf("=")+1, s.Length - s.IndexOf("=")-1);
Console.WriteLine(result);- 已建议为答案 CaillenModerator 2014年4月4日 9:40
- 已标记为答案 CaillenModerator 2014年4月11日 10:50
-
string s = "pageId=114776896;prototypeId=2;siteId=2; shopId=62112343; userid=444076877"; Regex reg = new Regex(@"userid=\d+"); Regex reg2 = new Regex(@"\d+"); Console.WriteLine(reg2.Match(reg.Match(s).Value).
ASP.NET Forum
Other Discussion Forums
FreeRice Donate
Issues to report
Free Tech Books Search and Download- 已标记为答案 CaillenModerator 2014年4月11日 10:50
-
你好。看了你的回答后不明白为什么要分reg reg2 呢?请指教,谢谢!
先取出userId+数字,然后取这个字符串中的数字。
煜诚海参专卖 淘宝店铺:http://jinweb.taobao.com
ASP.NET Forum
Other Discussion Forums
FreeRice Donate
Issues to report
Free Tech Books Search and Download