用正则表达式可以获得
确定网页中的连接string ex = "\"(http://\w*)\"";
Regex reg = new Regex( ex,RegexOptions.IgnoreCase );
MatchCollection matches = reg.Matches( 页面源文件的字符串 );
matches就是连接的集合
确定网页中的连接string ex = "\"(http://\w*)\"";
Regex reg = new Regex( ex,RegexOptions.IgnoreCase );
MatchCollection matches = reg.Matches( 页面源文件的字符串 );
matches就是连接的集合
来处理字符串正则的用途很多
这里只是调用,获取匹配一种格式字符的方法
先确定要获取的连接的样式
假定为
"http://..."
归纳正则为
string ex = "\"(http://\w*)\"";然后建立一个正则表达式对象
Regex reg = new Regex( ex,RegexOptions.IgnoreCase );
在命名空间System.Text.RegularExpressions下
RegexOptions.IgnoreCase表示匹配时忽略大小写MatchCollection matches = reg.Matches( 页面源文件的字符串 );
返回的就是所有形如
"http://..."的字符串你使用
if( matches != null )
{
foreach( Match match in matches )
{
string s =match.Value;
}
}
就可以遍历获取的字符串
string ex = "\"(http://\w*)\""; 这个表达式有问题,我改了还是有错,应该怎样改才对?
还有我想在textbox显示出来,但是类型不同,不能显示,怎样才能把它转成同类型?