Hi all i’m reading a file into a string variable, however i’m wondering what the best way to return only a specific element in the string into a new variable.
I have the following string data file:
[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
I only want to return the values for “Hosts”, so in the case above only Hosts = 3 (from [TEST1]) and Hosts = 4 (from [TEST2]). Any ideas would be most appreciated 🙂
I would just read line by line and look for
line.StartsWith("Hosts")– when that is true, pull out what you need.