【发布时间】:2014-05-31 12:24:17
【问题描述】:
文件包含
Londres, 14
Berlin, 11
New York, 9
Tokyo, 11
程序应该读取每个字符串,删除温度(寻找数字 在逗号之后)并找到4的平均温度,写下 屏幕,4个城市温度和平均温度。
我尝试过这样的事情,它只显示城市的名称,但我需要知道平均温度。我不知道怎么做。
string cami = "";
FileStream fs = new FileStream(@"C:\..\..\..\..\..\..\..\ex1.txt", FileMode.Open);
StreamReader sr = new StreamReader(fs);
while (sr.Peek() != -1)
{
cami = sr.ReadLine();
string[] s = cami.Split(',');
Console.WriteLine("{0}", s);
}
【问题讨论】:
-
你问的实际问题是什么?
-
使用正则表达式,如果卡住了就回来