private void button4_Clickobject sender EventArgs e函数实现读取容器listView1中起始状态、、接受符号、到达状态三列数据生成NFA文件listView1中数据大致如下:1 a 23 b 45 # 35 # 14 # 62 # 67 # 56 # 8
private void button4_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder();
// 添加文件头
sb.AppendLine("NFA");
// 添加起始状态
sb.AppendLine("S=" + listView1.Items[0].SubItems[0].Text);
// 添加接受符号
sb.AppendLine("A=" + listView1.Items[0].SubItems[1].Text);
// 添加到达状态
sb.AppendLine("F=" + listView1.Items[0].SubItems[2].Text);
// 添加转移函数
sb.AppendLine("T=");
foreach (ListViewItem item in listView1.Items)
{
sb.AppendLine(item.SubItems[0].Text + "," + item.SubItems[1].Text + "," + item.SubItems[2].Text);
}
// 保存文件
File.WriteAllText("NFA.txt", sb.ToString());
原文地址: https://www.cveoy.top/t/topic/cg1g 著作权归作者所有。请勿转载和采集!