标题:读取文件问题
只看楼主
奇异芒果
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-2-1
结帖率:0
已结贴  问题点数:20 回复次数:1 
读取文件问题
我是个初学者,看了段读取文件的代码,不太懂,请大神指点,下面的源代码有两个地方有问题
                        static void GetData()
        {
            StreamReader reader = new StreamReader(Environment.CurrentDirectory + "//观测值表.txt", Encoding.UTF8);
            
            string now_line;
            while(true)
            {
                now_line = reader.ReadLine();
                if (now_line != null)
                {
                    if (now_line[0] == '控')
                    {
                        char[] sep = { '(', ',', ')', ':', ':' };//请问这里表示什么意思
                        string[] data = now_line.Split(sep);//还有这里表示什么意思
                        
                        int num = (data.Length - 2) / 4;
                        for (int i = 0; i < num; i++)
                        {
                            Point nx = new Point();
                            nx.Id = int.Parse(data[1 + 4 * i]);
                            nx.Type = Point.PointTypes.起算点;
                            nx.X = double.Parse(data[3 + 4 * i]);
                            nx.Y = double.Parse(data[4 + 4 * i]);
                            nx.X0 = nx.X;
                            nx.Y0 = nx.Y;

                            KnownPoints.Add(nx);
                            StartPoints.Add(nx);
                            AllPoint.Add(nx);

                        }
                        
                        break;
                    }
                }
            }
搜索更多相关主题的帖子: 源代码 null 
2015-04-12 15:47
hkkuality
Rank: 2
等 级:论坛游民
威 望:2
帖 子:8
专家分:47
注 册:2015-3-16
得分:20 
    char[] sep = { '(', ',', ')', ':', ':' };//请问这里表示什么意思
    string[] data = now_line.Split(sep);//还有这里表示什么意思
根据 '( ',   ‘ ,' ,  ')' ,  ':' ,  ':',这些字符来分割字符串now_line,将其分割成为一个数组。
例如string now_line=" 1(2,3)4:5 ";
那么data={1,2,3,4,5}。就是data[0]=1;data[1]=2;data[2]=3;data[3]=4;data[4]=5;
懂吗?
2015-04-13 16:01



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-443900-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026214 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved