大家好,我正在将文件读入字符串变量,但是我想知道将字符串中的特定元素仅返回到新变量中的最佳方法是什么。
我有以下字符串数据文件:
[TEST1]
mem.consumed.average = 965608688
cpu.usagemhz.average = 18653
Hosts = 3
Points = 1535
RAM = 1535.96
CPU = 191.79
Powered_on VMs = 70
Powered_on RAM = 1049.02
Powered_on CPU = 410.15
Powered_on Points = 1051
Provisioned VMs = 74
Provisioned RAM = 1057.02
Provisioned CPU = 416.59
Provisioned Points = 1059
[TEST2]
mem.consumed.average = 298762549
cpu.usagemhz.average = 7782
Hosts = 4
Points = 1535
RAM = 1535.96
CPU = 191.79
Powered_on VMs = 54
Powered_on RAM = 303.00
Powered_on CPU = 266.29
Powered_on Points = 303
Provisioned VMs = 60
Provisioned RAM = 330.00
Provisioned CPU = 295.28
Provisioned Points = 330
我只想返回“Hosts”的值,所以在上面的例子中只有 Hosts = 3(来自 [TEST1])和 Hosts = 4(来自 [TEST2])。任何想法将不胜感激:)