[英]Save sections of text data to arrays
I have data to looks has the following format.我要查看的数据具有以下格式。 I'd like to create a new 2 column array for each "ran" with the respective ran name after the :.
我想为每个“运行”创建一个新的 2 列数组,在 : 之后使用各自的运行名称。
Ran: Efg (space between : and E)
1 50 (tab delimited)
2 52 (tab delimited)
3 54 (tab delimited)
Ran: pg2 (space between : and E)
1 40 (tab delimited)
2 60 (tab delimited)
3 80 (tab delimited)
Ran: 2 (space between : and E)
1 14 (tab delimited)
2 15 (tab delimited)
3 16 (tab delimited)
So far, I've a problem with using the following because it gives me an infinite loop, but I'm not sure how else to access the string resulttext from a previous到目前为止,我在使用以下内容时遇到了问题,因为它给了我一个无限循环,但我不知道如何从前一个访问字符串 resulttext
public void openDVHToolStripMenuItem_Click (object sender, EventArgs e){....}
public static string resulttext
{
get { return resulttext; }
}
Secondly, I've got the following so far to separate the name of the array-to-be.其次,到目前为止,我已经有了以下内容来分隔要成为的数组的名称。
private void button1_Click(object sender, EventArgs e)
{
Dictionary<string, List<string>> Darray = new Dictionary<string, List<string>>();
using (StringReader reader = new StringReader(resulttext))
{
string line;
string ran = "Ran:";
string region = "";
while (null != (line = reader.ReadLine()))
{
if (line.Contains(ran))
{
string[] splitHeader = line.Split(":".ToCharArray());
region = splitHeader[1].Trim();
}
else
{
if (!line.Contains(ran))
{
List<string> Dlist = new List<string>();
Darray.Add(region, Dlist);
}
}
}
foreach (var item in Darray)
{
richTextBox2.AppendText(item + Environment.NewLine);
}
}
}
I have to be able to call each array later and do some basic math on the values from both columns of numbers.我必须能够稍后调用每个数组并对来自两列数字的值进行一些基本的数学运算。
Any suggestions?有什么建议?
This:这个:
public static string resulttext
{
get { return resulttext; }
}
gives you an “infinite loop” because it is recursive;给你一个“无限循环”,因为它是递归的;
return resulttext
calls public static string resulttext
. return resulttext
调用public static string resulttext
。 Do this:做这个:
public static string ResultText { get; private set; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.