比如说有这样一个网址吧 http://community.csdn.net/Expert/topic/5526/552685&Page=2&Page=3 楼主是不是想得到这样的结果 http://community.csdn.net/Expert/topic/5526/552685&Page=2 http://community.csdn.net/Expert/topic/5526/552685&Page=3如果是,可以这样做,先取出Page后的数字,然后拼接字符串就行了 List<string> list = new List<string>(); MatchCollection mc = Regex.Matches(yourStr, @"Page=(\d+)", RegexOptions.IgnoreCase); foreach (Match m in mc) { list.Add(m.Groups[1].Value); }foreach(string s in list) { richTextBox2.Text += "http://community.csdn.net/Expert/topic/5526/552685&Page="+s + "\n"; }输出结果如上
如何把下面这个
......&Page=2&Page=3
替换成
......Page=后面均为数字
感觉可以用
string[] UrlID = AllType.Split('Page');
但这样提示:编译器错误信息: CS1012: 字符文本中的字符太多
不行吧
用 string[] UrlIDNext = System.Text.RegularExpressions.Regex.Split(AllType, "&Page");
http://community.csdn.net/Expert/topic/5526/552685&Page=2&Page=3
楼主是不是想得到这样的结果
http://community.csdn.net/Expert/topic/5526/552685&Page=2
http://community.csdn.net/Expert/topic/5526/552685&Page=3如果是,可以这样做,先取出Page后的数字,然后拼接字符串就行了
List<string> list = new List<string>();
MatchCollection mc = Regex.Matches(yourStr, @"Page=(\d+)", RegexOptions.IgnoreCase);
foreach (Match m in mc)
{
list.Add(m.Groups[1].Value);
}foreach(string s in list)
{
richTextBox2.Text += "http://community.csdn.net/Expert/topic/5526/552685&Page="+s + "\n";
}输出结果如上