如何提取并仅显示weatherzone中的当前温度?

How to extract and display only the current temperature in weatherzone?

通过 C# 代码从 weatherzone 获取数据:

string url = "http://rss.weatherzone.com.au/?u=12994-1285&lt=twcid&lc=160255&obs=1&fc=1";
XmlReader reader = XmlReader.Create(url);
SyndicationFeed feed = SyndicationFeed.Load(reader);
reader.Close();

获取当前天气:

var temperature = feed.Items.ToList()[0].Summary.Text.Trim();

输出:

<b>Temperature:</b> 33.0&#176;C
<img align="top" src="http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif" alt="steady"/>
<br />
<b>Feels like:</b> 38.0&#176;C<br />
<b>Dew point:</b> 23.0&#176;C
<img align="top" src="http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif" alt="steady"/>
<br />
<b>Relative humidity:</b> 56%<br />
<b>Wind:</b> NE at 18 km/h, gusting to  km/h
<img align="top" src="http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif" alt="steady"/>
<br />
<b>Rain:</b> mm since 9am<br />
<b>Pressure:</b> 1013.0 hPa
<img align="top" src="http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif" alt="steady"/>
<br />

问题:如何在此输出中获取温度?

你可以像这样粗暴地做一些事情:

var stringTemp = "<b>Temperature:</b> 33.0&#176;C <img align=\"top\" src=\"http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif\" alt=\"steady\"/> <br /> <b>Feels like:</b> 38.0&#176;C<br /> <b>Dew point:</b> 23.0&#176;C <img align=\"top\" src=\"http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif\" alt=\"steady\"/> <br /> <b>Relative humidity:</b> 56%<br /> <b>Wind:</b> NE at 18 km/h, gusting to km/h <img align=\"top\" src=\"http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif\" alt=\"steady\"/> <br /> <b>Rain:</b> mm since 9am<br /> <b>Pressure:</b> 1013.0 hPa <img align=\"top\" src=\"http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif\" alt=\"steady\"/> <br />";
var start = stringTemp.IndexOf("</b>");
var end = stringTemp.IndexOf("<img");
var temp = stringTemp.Substring(start + "</b>".Length, end - start - "<img".Length);

另一种方式

var temperature = "<b>Temperature:</b> 33.0&#176;C <img align=\"top\" src=\"http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif\" alt=\"steady\"/> <br /> <b>Feels like:</b> 38.0&#176;C<br /> <b>Dew point:</b> 23.0&#176;C <img align=\"top\" src=\"http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif\" alt=\"steady\"/> <br /> <b>Relative humidity:</b> 56%<br /> <b>Wind:</b> NE at 18 km/h, gusting to km/h <img align=\"top\" src=\"http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif\" alt=\"steady\"/> <br /> <b>Rain:</b> mm since 9am<br /> <b>Pressure:</b> 1013.0 hPa <img align=\"top\" src=\"http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif\" alt=\"steady\"/> <br />";

C#:

    private static string Temperature(string temperature)
    {
        try
        {
            string[] value = Regex.Split(temperature, "\n");
            string[] temp = Regex.Split(value[0], "</b> ");
            return temp[1].Substring(0, 2);
        }
        catch { return string.Empty; }
    }