![](/img/trans.png)
[英]How to save state of Windows Form Application (or save data in text boxes with arrays)
[英]Save sections of text data to arrays
我要查看的数据具有以下格式。 我想为每个“运行”创建一个新的 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)
到目前为止,我在使用以下内容时遇到了问题,因为它给了我一个无限循环,但我不知道如何从前一个访问字符串 resulttext
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);
}
}
}
我必须能够稍后调用每个数组并对来自两列数字的值进行一些基本的数学运算。
有什么建议?
这个:
public static string resulttext
{
get { return resulttext; }
}
给你一个“无限循环”,因为它是递归的; return resulttext
调用public static string resulttext
。 做这个:
public static string ResultText { get; private set; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.