【发布时间】:2016-01-07 14:14:59
【问题描述】:
我正在使用具有多行的 C# DataGridView(可能因用户输入而异)导出到纯文本文件,结果如下:
CompName,PowerOn,thin,Storage,acceptLic,verify,SSL,c:\test\myfile.img,root,P@ssw0rd,192.168.1.100
CompName,PowerOn,thin,Storage,acceptLic,verify,SSL,c:\test\myfile.img,root,P@ssw0rd,192.168.1.100
CompName,PowerOn,thin,Storage,acceptLic,verify,SSL,c:\test\myfile.img,root,P@ssw0rd,192.168.1.100
//...and more lines if user adds more
我想做的是解析文件并将每一行加载到一个变量中,我想将其附加到命令行可执行文件中,例如:
"C:\Program Files\Mytest\Mytest Tool\mytest.exe" -n=CompName --powerOn -dmode=convert -volume=storage1 --acceptLicense --noVerification --SSL c:\Users\me\Documents\down\myfile.img system1://root:myPassword@192.168.1.151
所以问题是这是怎么做到的?
我检查了许多示例,现在对于使用哪种方法来产生所需结果开始变得相当混乱。 (StreamReader、StringSplit、StringJoin 等等..)
我能够获取文件的内容以使用以下方法构建列表:
List<string> list = new List<string>();
using (StreamReader reader = new StreamReader(@"c:\foo\stest.txt"))
{
string line;
while ((line = reader.ReadLine()) != null)
{
list.Add(line); // Add to list.
Console.WriteLine(line); // Write to console.
StringBuilder builder = new StringBuilder();
//but where to from here ?
}
我在她的正确轨道上吗?我会很感激任何答案..
谢谢你
【问题讨论】: