[A basket of meals is very rare and original. Please indicate the source for reprintingHttp://www.cnblogs.com/wanghafan/archive/2012/02/09/2344276.html]
-- Simple example:
View Code
1 using System.Text;
2 using System.Text.RegularExpressions;
3
4 string str = "<img>123456789</img>";
5 string regexStr = @"<img>([^<]*)</img>";
6 Match mc = Regex.Match(str, regexStr, RegexOptions.IgnoreCase);
7 Response.Write(mc.Groups[1].Value);
-- Weather example:
View Code
1 using System. Text;
2 using System. Text. RegularExpressions;
3
4 string str = GetRequestString ("http://www.ntxnw.com.cn/tq.asp? S_type = 00 ", 8000, 1, Encoding. GetEncoding (" GB2312 "));
5 string regexStr = xxxxxxxxxxxxxxxxxxxx;
6 Match mc = Regex. Match (str, regexStr, RegexOptions. IgnoreCase );
7 this. divContent. InnerHtml = mc. Groups [1]. Value;
8 /// <summary>
9 // obtain the content of the specified remote webpage
10 /// </summary>
11 /// <param name = "strUrl"> remote webpage address to be searched </param>
12 /// <param name = "timeout"> set the timeout period, which is generally set to 8000 </param>
13 /// <param name = "enterType"> whether to output a line break. 0 indicates no output. 1 indicates a line break in the output text box. </param>
14 /// <param name = "EnCodeType"> encoding method </param>
15 /// <returns> </returns>
16 /// you can also consider static string
17 public string GetRequestString (string strUrl, int timeout, int enterType, System. Text. Encoding EnCodeType)
18 {
19 string strResult;
20 try
21 {
22 HttpWebRequest myReq = (HttpWebRequest) HttpWebRequest. Create (strUrl );
23 myReq. Timeout = timeout;
24 HttpWebResponse HttpWResp = (HttpWebResponse) myReq. GetResponse ();
25 Stream myStream = HttpWResp. GetResponseStream ();
26 StreamReader sr = new StreamReader (myStream, EnCodeType );
27 StringBuilder strBuilder = new StringBuilder ();
28 while (-1! = Sr. Peek ())
29 {
30 strBuilder. Append (sr. ReadLine ());
31 if (enterType = 1)
32 {
33 strBuilder. Append ("\ r \ n ");
34}
35}
36 strResult = strBuilder. ToString ();
37}
38 catch (Exception err)
39 {
40 strResult = "request error:" + err. Message;
41}
42 return strResult;
43}