首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

Chinajiyong进来一下。该如何解决

2012-04-07 
Chinajiyong进来一下。。。。。。string[] temp File.ReadAllLines(@C:\1.txt, Encoding.GetEncoding(GB231

Chinajiyong进来一下。。。。。。
string[] temp = File.ReadAllLines(@"C:\1.txt", Encoding.GetEncoding("GB2312"));
  temp = temp.ToList().Distinct().ToArray();
  File.WriteAllLines(@"C:\1.txt", temp);

例如数据是这样:
-------------------------------------------
00 2012.05 xxx 12345
00 2012.05 xxx 12300 
00 2012.05 xxx 12388
00 2012.06 xxx 12345
我只想判断12345这一列数据是否重复,请问代码该怎么变化呢?

[解决办法]

C# code
   //定义四个数组    ArrayList number = new ArrayList();    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {            string Path = Server.MapPath("info.txt");            getStr(Path);            for (int i = 0; i < number.Count; i++)            {                Response.Write(number[i].ToString()+" | ");                //这里将所有的最后一列数据取出来了,然后判断是否有重复应该很简单了                            }        }    }    //读取txt行中的每一个数据    public void getStr(string Path)    {        string strLine = "";        int i = 0;        try        {            StreamReader sr = new StreamReader(Path, Encoding.GetEncoding("GB2312"));            while ((strLine=sr.ReadLine()) != null)            {                string[] val = strLine.Split(' ');                //将数据保存在ArrayList集合中                number.Add(val[3]);                Response.Write("当前第"+i+"行:<br/>");                foreach (string s in val)                {                    Response.Write(s + "<br>");                }                i++;                Response.Write("<hr>");            }            sr.Dispose();            sr.Close();        }        catch        {        }    }
[解决办法]
探讨
string[] temp = File.ReadAllLines(@"C:\1.txt", Encoding.GetEncoding("GB2312"));
temp = temp.ToList().Distinct().ToArray();
File.WriteAllLines(@"C:\1.txt", temp);

例如数据是这样:
-------------------……

热点排行