日期:2014-05-17 浏览次数:20803 次
static void Main(string[] args) { string[][] Coor; //存放坐标的二维数组 Coor = new string[3][]; TextReader tr = new StreamReader(@"E:\nottingham\study\PRG\Projects\distance_P2P\distance_P2P\Coordinate.txt"); string rd=""; while ((rd = tr.ReadLine()) != null) { string[] row = rd.Split(','); } }
string[] rows = File.ReadAllLines(@"E:\nottingham\study\PRG\Projects\distance_P2P\distance_P2P\Coordinate.txt"); string[][] values = new string[rows.Length][]; for (int i = 0; i < rows.Length; i++) values[i] = rows[i].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); //以下是输出各元素的值 for (int i = 0; i < values.Length; i++) { for (int j = 0; j < values[i].Length; j++) Console.Write(values[i][j] + " "); Console.WriteLine(); }
------解决方案--------------------
string[] temp = System.IO.File.ReadAllLines("E:\\aaa.txt", System.Text.Encoding.GetEncoding("gb2312"));
Dictionary<int, product> dic = new Dictionary<int, product>();
foreach (string s in temp)
{
string[] pInfo = s.Split(',');
int id = int.Parse(pInfo[1]);
if (!dic.ContainsKey(id))
{
product p = new product();
p.id = id;
p.name = pInfo[2];
p.count = int.Parse(pInfo[3]);
p.remarks = pInfo[4];
dic.Add(id, p);
}
}
foreach (int i in dic.Keys)
{
product p = dic[i];
Console.WriteLine("Id:{0},name:{1},count:{2},remarks:{3},goodproductNo:{4},badproductNo:{5}", p.id, p.name, p.count, p.remarks, p.goodproductNo, p.badproductNo);
}