110,538
社区成员
发帖
与我相关
我的任务
分享
class Program
{
static void Main(string[] args)
{
string modle = "https://detail.xx.com/item.htm?uid=1549427204506&&id=124454445744&ali_trackid=2:mm_11054438_25822918_99096389:1549427448_213_1594518799";
string strRegex = @"id=(\d+)";
string id = RegexGetString(modle, strRegex);
Console.WriteLine(id);
Console.ReadKey();
}
static string RegexGetString(string pStrUrl, string pStrRegex)
{
string strSuccess = string.Empty;
string rsult = "";
Match match = Regex.Match(pStrUrl, pStrRegex);
if (match.Success)
{
rsult = match.Groups[1].Value;
}
bool b = Regex.IsMatch(rsult, @"\d{10,15}");//出于谨慎再次检验
if (b)
{
strSuccess = rsult;
}
return strSuccess;
}
}
string s = "https://detail.xx.com/item.htm?uid=1549427204506&&id=124454445744&ali_trackid=2:mm_11054438_25822918_99096389:1549427448_213_1594518799";
string r = HttpUtility.ParseQueryString(s)["id"];
Console.WriteLine(r);
Console.ReadKey();
// System.Net.HttpListenerRequest.Helpers
internal static void FillFromString(NameValueCollection nvc, string s, bool urlencoded, Encoding encoding)
{
int num = (s != null) ? s.Length : 0;
for (int i = (s.Length > 0 && s[0] == '?') ? 1 : 0; i < num; i++)
{
int num2 = i;
int num3 = -1;
while (i < num)
{
char c = s[i];
if (c == '=')
{
if (num3 < 0)
{
num3 = i;
}
}
else if (c == '&')
{
break;
}
i++;
}
string text = null;
string text2;
if (num3 >= 0)
{
text = s.Substring(num2, num3 - num2);
text2 = s.Substring(num3 + 1, i - num3 - 1);
}
else
{
text2 = s.Substring(num2, i - num2);
}
if (urlencoded)
{
nvc.Add((text == null) ? null : HttpListenerRequest.Helpers.UrlDecodeStringFromStringInternal(text, encoding), HttpListenerRequest.Helpers.UrlDecodeStringFromStringInternal(text2, encoding));
}
else
{
nvc.Add(text, text2);
}
if (i == num - 1 && s[i] == '&')
{
nvc.Add(null, "");
}
}
}