始终不会也找不到通过C#使用行和列的索引方式选取所需内容,求解答,折磨很久了。
文本内容:
Id,TestDt,Quantity,XFile,UID,CPN,MPN,UserName,Operator,OperatorId,ReelGroupName,DeviceId
4,2066-58-15 10:89:01,0,E:\Fix\2066-58-15\165742090_2.tiff,204105522;00001;464548546;1;76548848;4561596;205,,,Admin,,1,15,a
刚开始的时候通过逗号进行分割
string[] b = content.Split(',');
然后直接索引:
string reelID = b[4];
string QTY = b[2];
string value1 = b[16];
string value2 = b[14];
string str = $"ReelId={value1},QTY={value2}";
我想通过把文本内容赋给数组,然后把数组拆开。得到两个数组,再分别索引两个数组中的数据来
通过行和列的方式,选取出Quantity、CPN,以及第二行与其对应的值:“0”,“204105522;00001;464548546;1;76548848;4561596;205”
string str="Id,TestDt,Quantity,XFile,UID,CPN,MPN,UserName,Operator,OperatorId,ReelGroupName,DeviceId\n"+
"4,2066-58-15 10:89:01,0,E:\Fix\2066-58-15\165742090_2.tiff,204105522;00001;464548546;1;76548848;4561596;205,,,Admin,,1,15,a";
List<List<string>> b=new List<List<string>>();
string[] a=str.Split('\n');
foreach(string s in a)
{
List<string> lst=new List<string>(s.Split(','));
b.Add(lst);
}
string reelID = b[0][4];
string QTY = b[0][2];
文本解析为Table,第一行作为Table的列,第二行开始全部解析为数据行,操作Table的行和列,就能索引到你要的数据了