c#中实现查找功能
我用c#抓下一个网页,存在string中。我想在其中找到特定的句子,将其后面的数字提出写入txt。例如:BeijingAirPollutionmeasuredonSatu...
我用c#抓下一个网页,存在string中。我想在其中找到特定的句子,将其后面的数字提出写入txt。 例如:Beijing Air Pollution measured on Saturday 19:00: Beijing overall air quality index is 163<br>Beijing PM<sub>2.5</sub> (fine particulate matter) AQI is 163 - Beijing PM<sub>10</sub> (respirable particulate matter) AQI is 70
我想找到先找到Beijing PM<sub>2.5</sub> (fine particulate matter) AQI is然后把后面的163这个数字写入txt
要代码 展开
我想找到先找到Beijing PM<sub>2.5</sub> (fine particulate matter) AQI is然后把后面的163这个数字写入txt
要代码 展开
2个回答
展开全部
string s = "Beijing Air Pollution measured on Saturday 19:00: Beijing overall air quality index is 163<br>Beijing PM<sub>2.5</sub> (fine particulate matter) AQI is 163 - Beijing PM<sub>10</sub> (respirable particulate matter) AQI is 70";
string s2 = "Beijing PM<sub>2.5</sub> (fine particulate matter) AQI is ";
int index = s.IndexOf(s2);
s = s.Substring(index + s2.Length);
s2 = " - Beijing PM";
index = s.IndexOf(s2);
s = s.Substring(0, index);
File.WriteAllText("a.txt", s);
追问
s = s.Substring(index + s2.Length); 这一步就已经是定位到163这项了吧,为啥还有下面的
追答
因为163后面的,你也不想要吧,要去掉
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询