假设我们有一个包含以下数据(output.txt
)的txt文件:
MC Sim:
x1 = 28.87 x2 = 28.87 x3 = 24.02
C = 51 Iter = 1 S = 3.00 M= 26.77
C = 51 Iter = 2 S = 7.85 M= 32.70
C = 51 Iter = 3 S = 18.62 M= 46.85
MC Sim:
x1 = 28.87 x2 = 28.87 x3 = 19.65
C = 51 Iter= 1 S = 3.00 M = 22.28
C = 51 Iter= 2 S = 3.77 M = 25.10
C = 51 Iter= 3 S = 4.99 M = 28.89
C = 51 Iter= 4 S = 8.40 M = 35.78
C = 51 Iter= 5 S = 12.13 M = 46.22
C = 51 Iter= 6 S = 27.95 M = 72.74
我想阅读一些行并根据它包含的值创建指定的结构, 自动 。例如,假设我们想要使用 S &的值来创建以下结构。第3行和第5行之间 M :
Iter1.S = the value of S at line 3 (3.00)
Iter1.M = the value of M at line 3 (26.77)
Iter2.S = the value of S at line 4 (7.85)
Iter2.M = the value of M at line 4 (32.70)
Iter3.S = the value of S at line 5 (18.62)
Iter3.M = the value of M at line 5 (46.85)
请注意每个字段的名称应该是包含变量名称 Iter 的连接字符串及其值,例如Iter1 = Iter+1
。