日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

高手快帮忙,关于replace和正者表达式的问题

發布時間:2025/3/21 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 高手快帮忙,关于replace和正者表达式的问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我想把我獲取到的HTML里的所有的所有的<a href="替換成<a href="default2.aspx?str=,但是里面有雙引號,想問一下怎么用正者表達轉換啊
看下面代碼

?1using?System;
?2using?System.Data;
?3using?System.Configuration;
?4using?System.Collections;
?5using?System.Web;
?6using?System.Web.Security;
?7using?System.Web.UI;
?8using?System.Web.UI.WebControls;
?9using?System.Web.UI.WebControls.WebParts;
10using?System.Web.UI.HtmlControls;
11using?System.Net;
12using?System.Drawing;
13using?System.Drawing.Imaging;
14using?System.IO;
15
16
17public?partial?class?Default2?:?System.Web.UI.Page
18{
19????protected?void?Page_Load(object?sender,?EventArgs?e)
20????{
21????????GetWeather();
22????}

23????private?void?GetWeather()
24????{
25????????string?str?=?"http://z.zhongsou.com/gn.htm";
26????????try
27????????{
28????????????str?=?Request.Params["str"].ToString();
29
30????????}

31????????catch
32????????{
33?
34????????}

35????????????HttpWebRequest?request?=?(HttpWebRequest)WebRequest.Create(str);
36????????request.Method?=?"Get";
37????????request.ContentType?=?"application/x-www-form-urlencoded";
38????????WebResponse?response?=?request.GetResponse();
39????????Stream?s?=?response.GetResponseStream();
40????????StreamReader?sr?=?new?StreamReader(s,?System.Text.Encoding.GetEncoding("GB2312"));
41????????string?html?=?sr.ReadToEnd();
42????????s.Close();
43????????sr.Close();
44????????string?htm?=?html.Replace("<a?href=",?"<a?href='default2.aspx?str=");//我想把我獲取到的HTML里的所有的所有的<a?href="替換成<a?href="default2.aspx?str=,但是里面有雙引號,想問一下怎么用正者表達轉換啊
45????????System.IO.StreamWriter?sw;
46????????string?name?=?System.DateTime.Now.Date.ToShortDateString()+?System.DateTime.Now.Year.ToString()?+?System.DateTime.Now.Second.ToString();
47????????sw?=?new?System.IO.StreamWriter(Server.MapPath(name?+?".htm"),?false,?System.Text.Encoding.GetEncoding("GB2312"));
48????????sw.Write(htm);
49????????sw.Close();
50??????//??Response.Write(html);
51????????Response.Write(html);
52
53????}

54}

55

轉載于:https://www.cnblogs.com/sujingnan/archive/2008/03/19/1113382.html

總結

以上是生活随笔為你收集整理的高手快帮忙,关于replace和正者表达式的问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。