string a = "singfo.com/product/list63.html";
string b = a.Substring(a.IndexOf("63"),"63".Length) .ToString();
public static int GetNum(string s)
{
Regex r = new Regex("(?
Match m = r.Match(s);
if (m.Success)
{
return Convert.ToInt32(m.Groups["num"].Value);
}
throw new ArgumentException("没有匹配的数字!");
}
substring(a,a.Indexof(b),b.Length)
使用正则方法提取:
string strHTML = @"singfo.com/product/list63453.html";
string pattern = @"list\d*\.html$";
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
string outString = "";
System.Text.RegularExpressions.MatchCollection mc = reg.Matches(strHTML);
if (mc.Count > 0)
{
foreach (System.Text.RegularExpressions.Match m in mc)
{
outString = m.Value.ToString();
}
}
outString = outString.Replace("list", "").Replace(".html", "");
MessageBox.Show(outString);
list前面的是固定的?