C# 如何提取每个输出的最后一个值?
这是我的文本文件的内容,它由一个名称组成,如“output1”后接一系列数字,“output2”后接一系列数字等等,由一个空格分隔……我想提取每个输出的最后一个值。我该怎么做?例如,我想将“output1”的值提取为29.933215(即“output2”之前的值),将“output2”的值提取为379.983559C# 如何提取每个输出的最后一个值?,c#,C#,这是我的文本文件的内容,它由一个名称组成,如“output1”后接一系列数字,“output2”后接一系列数字等等,由一个空格分隔……我想提取每个输出的最后一个值。我该怎么做?例如,我想将“output1”的值提取为29.933215(即“output2”之前的值),将“output2”的值提取为379.983559 文本文件的内容如下所示: 输出1 30.000000 29.999969 29.9990729.9997829.9995329.999039 29.998047 29.9960
- 文本文件的内容如下所示:
Dictionary<string, double> dic = new Dictionary<string,double>();
string[] items = str.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
string lastOutput = "";
for(int index = 0; index < items.Length; index++)
{
if(items[index].Contains("output"))
{
if(lastOutput.Length > 0 && index > 0)
{
dic.Add(lastOutput, double.Parse(items[index - 1]));
}
lastOutput = items[index];
}
}
dic.Add(lastOutput, double.Parse(items[items.Length-1]));
string[]items=str.Split(“.ToCharArray(),StringSplitOptions.removeMptyEntries”);
字符串lastOutput=“”;
for(int index=0;index使用StreamReader的ReadToEnd方法。这将返回一个由数据组成的字符串。拆分字符串并将其存储到数组中。我想你可以从这里开始。outputX总是从一个新的行开始吗?+1用于不给程序员灌输应该很容易做到的代码。