![](/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.