usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
usingSystem.Drawing;
usingMSXML2;
usingSystem.Text.RegularExpressions;
namespacewenweifeng
{
/**//// <summary><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> ///CaiJi的摘要说明<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"> /// </summary>
public classCaiJi
{
publicCaiJi()
{
//
//TODO:在此处添加构造函数逻辑
//
}
~CaiJi()
{
Dispose();
}
public voidDispose()
{
GC.SuppressFinalize(this);
}
日期随机函数#region日期随机函数
/**//**********************************
*函数名称:DateRndName
*功能说明:日期随机函数
*参数:ra:随机数
*调用示例:
*GetRemoteObjo=newGetRemoteObj();
*Randomra=newRandom();
*strings=o.DateRndName(ra);
*Response.Write(s);
*o.Dispose();
*********************************/
/**//// <summary><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> ///日期随机函数<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> /// </summary>
/// 随机数
/// <returns></returns>
public stringDateRndName(Randomra)
{
DateTimed=DateTime.Now;
strings= null,y,m,dd,h,mm,ss;
y=d.Year.ToString();
m=d.Month.ToString();
if(m.Lengthdd=d.Day.ToString();
if(dd.Lengthh=d.Hour.ToString();
if(h.Lengthmm=d.Minute.ToString();
if(mm.Lengthss=d.Second.ToString();
if(ss.Lengths+=y+ ',' +m+ ',' +dd+ ',' +h+ "-" +mm+ "-" +ss;
s+=ra.Next(1000000,9999999).ToString();
returns;
}
#endregion
取得文件后缀#region取得文件后缀
/**//**********************************
*函数名称:GetFileExtends
*功能说明:取得文件后缀
*参数:filename:文件名称
*调用示例:
*GetRemoteObjo=newGetRemoteObj();
*stringurl=@"http://www.baidu.com/img/logo.gif";
*strings=o.GetFileExtends(url);
*Response.Write(s);
*o.Dispose();
*********************************/
/**//// <summary><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> ///取得文件后缀<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> /// </summary>
/// 文件名称
/// <returns></returns>
public stringGetFileExtends(stringfilename)
{
stringext= null;
if(filename.IndexOf('.')> 0)
{
string[]fs=filename.Split('.');
ext=fs[fs.Length- 1];
}
returnext;
}
#endregion
获取远程文件源代码#region获取远程文件源代码
/**//**********************************
*函数名称:GetRemoteHtmlCode
*功能说明:获取远程文件源代码
*参数:Url:远程url
*调用示例:
*GetRemoteObjo=newGetRemoteObj();
*stringurl=@"http://www.baidu.com";
*strings=o.GetRemoteHtmlCode(url);
*Response.Write(s);
*o.Dispose();
*********************************/
/**//// <summary><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> ///获取远程文件源代码<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> /// </summary>
/// 远程url
/// <returns></returns>
public stringGetRemoteHtmlCode(stringUrl)
{
strings= "";
MSXML2.XMLHTTP_xmlhttp= newMSXML2.XMLHTTPClass();
_xmlhttp.open("GET",Url,false,null,null);
_xmlhttp.send("");
if(_xmlhttp.readyState== 4)
{
s=System.Text.Encoding.Default.GetString((byte[])_xmlhttp.responseBody);
}
returns;
}
#endregion
保存远程文件#region保存远程文件
/**//**********************************
*函数名称:RemoteSave
*功能说明:保存远程文件
*参数:Url:远程url;Path:保存到的路径
*调用示例:
*GetRemoteObjo=newGetRemoteObj();
*strings="";
*stringurl=@"http://www.baidu.com/img/logo.gif";
*stringpath=Server.MapPath("Html/");
*s=o.RemoteSave(url,path);
*Response.Write(s);
*o.Dispose();
*******************************/
/**//// <summary><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> ///保存远程文件<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> /// </summary>
/// 远程url
/// 保存到的路径
/// <returns></returns>
public stringRemoteSave(stringUrl,stringPath)
{
Randomra= newRandom();
stringnewfilename= string.Empty;
stringStringFileName=DateRndName(ra)+ "." +GetFileExtends(Url);
if(GetFileExtends(Url).Trim().ToLower()!= "jpg")
newfilename=StringFileName;
else
newfilename=DateRndName(ra)+ "Addpic." +GetFileExtends(Url);
stringStringFilePath=Path+StringFileName;
stringnewfilepath=Path+newfilename;
stringretname= string.Empty;
try
{
MSXML2.XMLHTTP_xmlhttp= newMSXML2.XMLHTTPClass();
_xmlhttp.open("GET",Url,false,null,null);
_xmlhttp.send("");
if(_xmlhttp.readyState== 4)
{
if(System.IO.File.Exists(StringFilePath))
System.IO.File.Delete(StringFilePath);
System.IO.FileStreamfs= newSystem.IO.FileStream(StringFilePath,System.IO.FileMode.CreateNew);
System.IO.BinaryWriterw= newSystem.IO.BinaryWriter(fs);
w.Write((byte[])_xmlhttp.responseBody);
w.Close();
fs.Close();
if(GetFileExtends(Url).Trim().ToLower()== "jpg")
{
functionmyfunction= newfunction();
//myfunction.AddShuiYinWord(StringFilePath,newfilepath);
servicemyserver=newservice();
myfunction.AddShuiYinPic(StringFilePath,newfilepath,HttpContext.Current.Server.MapPath(myserver.myweblogo));
}
}
else
throw newException(_xmlhttp.statusText);
}
catch(Exceptionex)
{
}
returnnewfilename;
}
#endregion
替换网页中的换行和引号#region替换网页中的换行和引号
/**//**********************************
*函数名称:ReplaceEnter
*功能说明:替换网页中的换行和引号
*参数:HtmlCode:html源代码
*调用示例:
*GetRemoteObjo=newGetRemoteObj();
*stringUrl=@"http://www.baidu.com";
*stringHtmlCode=o.GetRemoteHtmlCode(Url);
*strings=o.ReplaceEnter(HtmlCode);
*Response.Write(s);
*o.Dispose();
*********************************/
/**//// <summary><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> ///替换网页中的换行和引号<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> /// </summary>
/// HTML源代码
/// <returns></returns>
public stringReplaceEnter(stringHtmlCode)
{
strings= "";
if(HtmlCode== null ||HtmlCode== "")
s= "";
else
s=HtmlCode.Replace("\"","");
s=s.Replace("\r","");
s=s.Replace("\n","");
returns;
}
#endregion
执行正则提取出值#region执行正则提取出值
/**//**********************************
*函数名称:GetRegValue
*功能说明:执行正则提取出值
*参数:HtmlCode:html源代码
*调用示例:
*GetRemoteObjo=newGetRemoteObj();
*stringUrl=@"http://www.baidu.com";
*stringHtmlCode=o.GetRemoteHtmlCode(Url);
*strings=o.ReplaceEnter(HtmlCode);
*stringReg="
.+?";
*stringGetValue=o.GetRegValue(Reg,HtmlCode)
*Response.Write(GetValue);
*o.Dispose();
*********************************/
/**//// <summary><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> ///执行正则提取出值<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> /// </summary>
/// 正则表达式
/// HtmlCode源代码
/// <returns></returns>
public stringGetRegValue(stringRegexString,stringRemoteStr)
{
stringMatchVale= "";
Regexr= newRegex(RegexString);
Matchm=r.Match(RemoteStr);
if(m.Success)
{
MatchVale=m.Value;
}
returnMatchVale;
}
#endregion
替换HTML源代码#region替换HTML源代码
/**//**********************************
*函数名称:RemoveHTML
*功能说明:替换HTML源代码
*参数:HtmlCode:html源代码
*调用示例:
*GetRemoteObjo=newGetRemoteObj();
*stringUrl=@"http://www.baidu.com";
*stringHtmlCode=o.GetRemoteHtmlCode(Url);
*strings=o.ReplaceEnter(HtmlCode);
*stringReg=".+?";
*stringGetValue=o.GetRegValue(Reg,HtmlCode)
*Response.Write(GetValue);
*o.Dispose();
*********************************/
/**//// <summary><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> ///替换HTML源代码<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> /// </summary>
/// html源代码
/// <returns></returns>
public stringRemoveHTML(stringHtmlCode)
{
stringMatchVale=HtmlCode;
foreach(MatchsinRegex.Matches(HtmlCode,"<.>"))<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"><img src="http://www.cnblogs.com/Images/dot.gif">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">MatchVale=MatchVale.Replace(s.Value,"");<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">}<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> returnMatchVale;<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">}<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"> #endregion<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"> 匹配页面的链接#region匹配页面的链接<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"> /**//**********************************<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*函数名称:GetHref<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*功能说明:匹配页面的链接<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*参数:HtmlCode:html源代码<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*调用示例:<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*GetRemoteObjo=newGetRemoteObj();<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*stringUrl=@"http://www.baidu.com";<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*stringHtmlCode=o.GetRemoteHtmlCode(Url);<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*strings=o.GetHref(HtmlCode);<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*Response.Write(s);<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*o.Dispose();<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">*********************************/<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"> /**//// <summary><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> ///获取页面的链接正则<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> /// </summary><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> /// <param> <br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"> /// <returns></returns><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> public stringGetHref(stringHtmlCode)<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"><img src="http://www.cnblogs.com/Images/dot.gif">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> stringMatchVale= "";<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> stringReg= @"(h|H)(r|R)(e|E)(f|F)*=*('|"")?((\w|\\|\/|\.|:|-|_)+)[\S]*";<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> foreach(MatchminRegex.Matches(HtmlCode,Reg))<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"><img src="http://www.cnblogs.com/Images/dot.gif">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">MatchVale+=(m.Value).ToLower().Replace("href=","").Trim()+ "|";<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">}<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> returnMatchVale;<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">}<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"> #endregion<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"> 匹配页面的图片地址#region匹配页面的图片地址<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"> /**//**********************************<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*函数名称:GetImgSrc<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*功能说明:匹配页面的图片地址<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*参数:HtmlCode:html源代码;imgHttp:要补充的http.当比如:<img>则要补充http://www.baidu.com/,当包含http信息时,则可以为空<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*调用示例:<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*GetRemoteObjo=newGetRemoteObj();<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*stringUrl=@"http://www.baidu.com";<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*stringHtmlCode=o.GetRemoteHtmlCode(Url);<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*strings=o.GetImgSrc(HtmlCode,"http://www.baidu.com/");<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*Response.Write(s);<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*o.Dispose();<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">*********************************/<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"> /**//// <summary><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> ///匹配页面的图片地址<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> /// </summary><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> /// <param> <br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> /// <param>要补充的http://路径信息<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"> /// <returns></returns><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> public stringGetImgSrc(stringHtmlCode,stringimgHttp)<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"><img src="http://www.cnblogs.com/Images/dot.gif">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> stringMatchVale= "";<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> stringReg= @"<img.>";<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> foreach(MatchminRegex.Matches(HtmlCode.ToLower(),Reg))<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"><img src="http://www.cnblogs.com/Images/dot.gif">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">MatchVale+=GetImg((m.Value).ToLower().Trim(),imgHttp)+ "|";<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">}<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> returnMatchVale;<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">}<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"> /**//// <summary><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> ///匹配<img>中的图片路径实际链接<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> /// </summary><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> /// <param> <img>字符串<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"> /// <returns></returns><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> public stringGetImg(stringImgString,stringimgHttp)<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"><img src="http://www.cnblogs.com/Images/dot.gif">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> stringMatchVale= "";<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> stringReg= @"src=.+\.(bmp|jpg|gif|png|)";<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> foreach(MatchminRegex.Matches(ImgString.ToLower(),Reg))<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"><img src="http://www.cnblogs.com/Images/dot.gif">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">MatchVale+=(m.Value).ToLower().Trim().Replace("src=","");<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">}<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> if(MatchVale.IndexOf(".net")!= -1 ||MatchVale.IndexOf(".com")!= -1 ||MatchVale.IndexOf(".org")!= -1 ||MatchVale.IndexOf(".cn")!= -1 ||MatchVale.IndexOf(".cc")!= -1 ||MatchVale.IndexOf(".info")!= -1 ||MatchVale.IndexOf(".biz")!= -1 ||MatchVale.IndexOf(".tv")!= -1)<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> return(MatchVale);<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> else<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> return(imgHttp+MatchVale);<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">}<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"> #endregion<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"> 替换通过正则获取字符串所带的正则首尾匹配字符串#region替换通过正则获取字符串所带的正则首尾匹配字符串<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"> /**//**********************************<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*函数名称:GetHref<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*功能说明:匹配页面的链接<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*参数:HtmlCode:html源代码<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*调用示例:<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*GetRemoteObjo=newGetRemoteObj();<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*stringUrl=@"http://www.baidu.com";<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*stringHtmlCode=o.GetRemoteHtmlCode(Url);<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*strings=o.RegReplace(HtmlCode,"<title>","</title>");<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*Response.Write(s);<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">*o.Dispose();<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">*********************************/<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"> /**//// <summary><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> ///替换通过正则获取字符串所带的正则首尾匹配字符串<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> /// </summary><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> /// <param>要替换的值<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> /// <param>正则匹配的首字符串<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> /// <param>正则匹配的尾字符串<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"> /// <returns></returns><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> public stringRegReplace(stringRegValue,stringregStart,stringregEnd)<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"><img src="http://www.cnblogs.com/Images/dot.gif">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> strings=RegValue;<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> if(RegValue!= "" &&RegValue!= null)<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"><img src="http://www.cnblogs.com/Images/dot.gif">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> if(regStart!= "" &&regStart!= null)<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"><img src="http://www.cnblogs.com/Images/dot.gif">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">s=s.Replace(regStart,"");<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">}<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> if(regEnd!= "" &&regEnd!= null)<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top"><img src="http://www.cnblogs.com/Images/dot.gif">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top">s=s.Replace(regEnd,"");<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">}<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">}<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"> returns;<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">}<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"> #endregion<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">}<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top">}</img.></.>