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

时间:2013-12-17 09:09:06

标签: c# string

我有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";

我想写两个用户输入数字ex:(2-8)或(1-250)之间的字符串 我该怎么办?

由于

1 个答案:

答案 0 :(得分:1)

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

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