想请教如何按特定字符读取txt文件 比如有这么一行命令gdc,targetFunction,times,time存在txt文件里面我想逐个解析它比如读出第一个逗号前面的命令然后读第二个逗号前面的命令在读第三个逗号前面的命令。。请教高手 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System.IO;StreamReader reader = new StreamReader("FilePath"); String command = reader.ReadLine(); String[] commands = command.Split(','); String strGDC = commands[0]; // gdc //... 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(); 求助:textbox中的光标位置? C#调用VFP dll的问题,请大侠们帮看看。 如何将波形控件的波形显示由从右向左,改为从左向右改为从左向右? 正则表达式难题(在线等!急) 如何实现TextBox控制入力行数??? 关于VS2003中使用WinForm时出现的界面混乱情况 datagrid嵌套怎么再嵌套的datagrid里实现编辑功能呢 求一个关于数字字符串格式的函数!! 急!!!! C++ 递推 请问一个DataAdapter的Update方法的问题 如何在类里调用类外部的方法 这是什么加密方式
String command = reader.ReadLine();
String[] commands = command.Split(','); String strGDC = commands[0]; // gdc
//...
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();