使用haxe语言为文件中的每一行添加数字

时间:2018-03-06 17:30:30

标签: file numbers haxe

需要一些帮助,编写一个程序来读取文件中的文本,但是会 在每行的开头加上一个数字,使每行按升序编号 例如:

文件1

B'/ P>

C

我想看到的内容:

1:a

2:b

3:c

1 个答案:

答案 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