需要一些帮助,编写一个程序来读取文件中的文本,但是会 在每行的开头加上一个数字,使每行按升序编号 例如:
文件1
一
B'/ P>
C
我想看到的内容:
1:a
2:b
3:c
答案 0 :(得分:1)
过程:
string[] allLines = File.ReadAllLines(Server.MapPath("App_Data/Classes.txt"))
foreach(string line in allLines){
string[] parts = line.Split(',');
TableRow row = new TableRow();
TableCell number = new TableCell();
TableCell lesson = new TableCell();
TableCell number2 = new TableCell();
TableCell lesson2 = new TableCell();
TableCell number3 = new TableCell();
TableCell lesson3 = new TableCell();
TableCell number4 = new TableCell();
TableCell lesson4 = new TableCell();
TableCell number5 = new TableCell();
TableCell lesson5 = new TableCell();
if (parts[1] == "Monday" & parts[0] == "5a klase")
{
number.Text = parts[2];
lesson.Text = parts[3];
}
if (parts[1] == "Tuesday" & parts[0] == "5a klase")
{
number2.Text = parts[2];
lesson2.Text = parts[3];
}
if (parts[1] == "Wednesday" & parts[0] == "5a klase")
{
number3.Text = parts[2];
lesson3.Text = parts[3];
}
if (parts[1] == "Thursday" & parts[0] == "5a klase")
{
number4.Text = parts[2];
lesson4.Text = parts[3];
}
if (parts[1] == "Friday" & parts[0] == "5a klase")
{
number5.Text = parts[2];
lesson5.Text = parts[3];
}
row.Cells.Add(number);
row.Cells.Add(lesson);
row.Cells.Add(number2);
row.Cells.Add(lesson2);
row.Cells.Add(number3);
row.Cells.Add(lesson3);
row.Cells.Add(number4);
row.Cells.Add(lesson4);
row.Cells.Add(number5);
row.Cells.Add(lesson5);
Table1.Rows.Add(row);
String
Array<String>
任何String
目标的示例代码:
sys