比如有这么一行命令
gdc,targetFunction,times,time存在txt文件里面我想逐个解析它
比如读出第一个逗号前面的命令
然后读第二个逗号前面的命令
在读第三个逗号前面的命令
。。
请教高手

解决方案 »

  1.   

    using System.IO;StreamReader reader = new StreamReader("FilePath");
                String command = reader.ReadLine();
                String[] commands = command.Split(',');            String strGDC = commands[0]; // gdc
                //...
      

  2.   

    1 先全部读出 然后SPLIT切分
    System.IO.StreamReader _Sr = new System.IO.StreamReader(@"C:\123.txt");            string _Command=_Sr.ReadToEnd().Split(',');            _Sr.Close();2 一个字一个字的读 
     System.IO.StreamReader _Sr = new System.IO.StreamReader(@"C:\123.txt");   
                int _ReadByte =_Sr.Read();
                IList<string> _Command = new List<string>();
                string _TempCommand = "";
                while (_ReadByte != -1)
                {
                    if ((char)_ReadByte != ',')
                    {
                        _TempCommand += (char)_ReadByte;
                    }
                    else
                    {
                        _Command.Add(_TempCommand);
                        _TempCommand = "";
                    }
                    _ReadByte = _Sr.Read();
                }
                if (_TempCommand.Length != 0) _Command.Add(_TempCommand);
                _Sr.Close();