Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a text file called reports.txt that I am able to get to open on Rich Text but is there anyway that I can get it to open but only display selected text

the file contains CPU Score: 322 CPU General: 708473 CPU Targeted: 341030088 RAM Score: 135 RAM Size (MB): 4001 RAM Speed (MB/s): 12144 GPU Compute (GFLOPS): 181 Disk Score: 49 Disk Write (MB/s): 117 Disk Read (MB/s): 322

for example i would like it to display 322, 135, 49 in like a text box. You are able to do this would anyone be able to help me please.

What I have tried:

I have tryed rich text but i only seem to be able to open the whole txt file.
Posted
Updated 2-Sep-18 12:10pm

You could try a regex:
(?<=Score:\s+)\d+(?=\s+)
Should do it
 
Share this answer
 
Comments
Chris Dewey 2-Sep-18 14:15pm    
Hi OriginalGriff, Thank you for your comment. Not heard of regex before i am a begininer were would i put that bit of code. I have the following so far

private void novabnt_Click(object sender, EventArgs e)
{

TextReader reader = new StreamReader(@"C:\source\results.txt");

richTextBox1.Text = reader.ReadToEnd();

reader.Close();
}
OriginalGriff 3-Sep-18 4:08am    
OK - so the first thing you need to do is look at the actual data file (or several different files if possible) because it's very important to know exactly what you have got to work with.
For example, the code to deal with this:
<pre lang="text">CPU Score: 322 CPU General: 708473 CPU Targeted: 341030088 RAM Score: 135 RAM Size (MB): 4001 RAM Speed (MB/s): 12144 GPU Compute (GFLOPS): 181 Disk Score: 49 Disk Write (MB/s): 117 Disk Read (MB/s): 322
Is different from the code to deal with this:
<pre lang="text">CPU Score: 322
CPU General: 708473
CPU Targeted: 341030088
RAM Score: 135
RAM Size (MB): 4001
RAM Speed (MB/s): 12144
GPU Compute (GFLOPS): 181
Disk Score: 49
Disk Write (MB/s): 117
Disk Read (MB/s): 322Because in the second it's already broken into lines, and that makes your job a whole load easier!
And if you have multiple samples, you can check how much the data in the file changes between "runs" - is it always in the same order? Are the items always all present, and no others? Can you rely on "Score: ", or do you need to be more specific? Is there any other data in the file at all?

Check that lot, and get back to me - you don't necessarily have to learn Regular Expressions (or "Regex" for short) yet - there may be simple ways to handle this that fits within your current knowledge (not that I have idea what you do and don;t know how to do!)
    private void novabnt_Click(object sender, EventArgs e)
{
    var dict = File.ReadAllLines(@"c:\source\reports.txt")
    .Select(f => f.Split(':'))
    .Select(f => new
    {
        Name = f[0].Trim(),
        Value = f[1].Trim()
    })
    .ToDictionary(f => f.Name, f => f.Value);

    txtrams.Text = String.Empty;
    txtrams.AppendText(dict["RAM Score"]);
    txtCPUS.Text = String.Empty;
    txtCPUS.AppendText(dict["CPU Score"]);
    txthdds.Text = String.Empty;
    txthdds.AppendText(dict["Disk Score"]);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900