仅显示值在2个用户输入数字之间的字符串

本文关键字:数字 之间 字符串 输入 用户 显示 2个 | 更新日期: 2024-10-22 10:29:49

我有600行字符串,全部编号为ex:

contents[0] = "HALTUNG;" + textBox2.Text + "-01" + " " + textBox2.Text + "-02;" + textBox2.Text + "-01;" + textBox2.Text + "-02";
contents[1] = "HALTUNG;" + textBox2.Text + "-02" + " " + textBox2.Text + "-03;" + textBox2.Text + "-02;" + textBox2.Text + "-03";
contents[2] = "HALTUNG;" + textBox2.Text + "-03" + " " + textBox2.Text + "-04;" + textBox2.Text + "-03;" + textBox2.Text + "-04";
contents[3] = "HALTUNG;" + textBox2.Text + "-04" + " " + textBox2.Text + "-05;" + textBox2.Text + "-04;" + textBox2.Text + "-05";
contents[4] = "HALTUNG;" + textBox2.Text + "-05" + " " + textBox2.Text + "-06;" + textBox2.Text + "-05;" + textBox2.Text + "-06";
contents[5] = "HALTUNG;" + textBox2.Text + "-06" + " " + textBox2.Text + "-07;" + textBox2.Text + "-06;" + textBox2.Text + "-07";

我想将2个用户输入数字(例如:(2-8)或(1-250)之间的字符串写入文件我该怎么做?

感谢

仅显示值在2个用户输入数字之间的字符串

您可以使用linq Skip and Take方法,我假设Start有起始行号,End有结束行号。

var lines = contents.Skip(Start).Take(End-Start);