截取天气预报 private string GetWeather() ... { string weather =""; String respHTML = GetWeatherData(); if (respHTML.IndexOf("Humidity")>0) ...{ Regex r = new Regex("<.+?>"); weather = r.Replace(respHTML,""); int t1 = weather.IndexOf("**** "); int t2 = weather.IndexOf("****"); weather = weather.Replace(" ",""); if(t2 > t1) ...{ weather = weather.Substring(t1-200,300); } else ...{ weather = weather.Substring(t2,t1-t2); } return weather; } else ...{ return ""; } } private string GetWeatherData() ... { String respHTML=""; try ...{ WebRequest wReq = WebRequest.Create("天气预报网址"); WebResponse wResp = wReq.GetResponse(); Stream respStream = wResp.GetResponseStream(); StreamReader reader = new StreamReader(respStream, Encoding.Default); respHTML = reader.ReadToEnd(); wResp.Close(); } catch (Exception e) ...{ return e.ToString(); } return respHTML; }