tags:

views:

40

answers:

2

Hi all,

I'm trying to read specific values from the text file (below):

Current Online Users: 0
Total User Logins: 0
Server Uptime: 0 day, 0 hour, 0 minute
Downloaded Amount: 0.000 KB
Uploaded Amount: 0.000 MB
Downloaded Files: 0
Uploaded Files: 0
Download Bandwidth Utilization: 0.00 KB/s
Upload Bandwidth Utilization: 000.00 KB/s

I can read the file to an array:

   Dim path As String = "C:\Stats.txt"
   Dim StringArrayOfTextLines() As String = System.IO.File.ReadAllLines(path)

How do I store only the data I require in the array? I've tried split and substring but cannot work out a usable method - I need on the text after the colon for each line.

I was thinking, I only require the numerical data, can this be extracted from each line rather than just splitting into an array?

Thanks.

A: 

ReadAllLines does just what it says it does. You have to iterate over the results. To read the data you want directly, you have to write the code to use a System.IO.StreamReader (and it's ReadLine() function) or even just a base System.IO.FileStream.

Joel Coehoorn
+1  A: 

To capture everything after the colon you just need to split on it and take the second element of each result:

For Each s In StringArrayOfTextLines
    Console.WriteLine(s.Split(":")(1).Trim())
Next

If you want to do that as you read the data you'll need to use a StreamReader like Joel suggested.

Ahmad Mageed