我的数据看起来有以下格式。我想为每个“run”创建一个新的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)
到目前为止,我在使用以下内容时遇到了问题,因为它给了我一个无限循环,但我不确定如何从以前的
访问字符串结果文本public void openDVHToolStripMenuItem_Click (object sender, EventArgs e){....}
public static string resulttext
{
get { return resulttext; }
}
其次,到目前为止,我已经有了以下内容来分离数组的名称。
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);
}
}
}
我必须能够稍后调用每个数组,并对两列数字的值进行一些基本的数学运算。
有什么建议吗?
答案 0 :(得分:1)
此:
public static string resulttext
{
get { return resulttext; }
}
给你一个“无限循环”,因为它是递归的; return resulttext
来电public static string resulttext
。这样做:
public static string ResultText { get; private set; }