Results 1 to 4 of 4

Thread: Check if string has bigger value

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2011
    Posts
    115

    Check if string has bigger value

    I need to check for a string if it has bigger value then the one in text file .

    My code is like this :

    Code:
    String vl = Scores();
    if (string.IsNullOrEmpty(vl) == true)
    {
    string text = System.IO.File.ReadAllText(@"test.txt");
    textBox3.Text = text;
    VM = new VMessages("Wmedit//Edit");
    VM.sendText(textBox3.Text);
    VM.sendKey(Keys.Enter); 
    }
    else
    {
    System.IO.StreamWriter file = new System.IO.StreamWriter(@"test.txt");
    file.WriteLine(vl);
    file.Close();
    string text = System.IO.File.ReadAllText(@"test.txt");
    textBox3.Text = text;
    VM = new VMessages("Wmedit//Edit");
    VM.sendText(textBox3.Text);
    VM.sendKey(Keys.Enter);
    }
    }
    now it checks if it has zero value in the string, when it is 0 it reads from test.txt and sends it to the window. But I need is it has to check if it is 0 + if it is not 0 is it bigger value or not. If it is bigger then reads again from the test.txt .

    How can I do this...

    My string pharse code is like this:

    Code:
    try
    {
    String source = File.ReadAllText(textBox1.Text + @"\result.txt");
    source = source.Replace("\r", "").Replace("\n", "");
    GroupCollection[ ] gr = (from Match it in Regex.Matches(source, @"\s*1\.\s+""([^""]*)"" Name![^-]*Value \(([^\)]+)\)[^-]*Distance \: ([0-9\.]+) meters\s*", RegexOptions.IgnoreCase)
    where it.Groups != null && it.Groups.Count == 4
    select it.Groups).ToArray( );
    if (gr == null || gr.Length == 0) { return null; }
    Double max = (from GroupCollection it in gr select Convert.ToDouble(it[2].Value)).Max( );
    String res = (from GroupCollection it in gr where Convert.ToDouble(it[2].Value) == max select it[-1] + "Congratulation : " + it[1] + " :::...Score...::: " + it[2] + " ...:::Distance Meters...::: " + it[3]).First();
    return res;
    }
    catch
    {
    throw;
    }
    finally
    {
    } 
    }
    thanks..

  2. #2
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Check if string has bigger value

    Code:
    string tfile = System.IO.File.ReadAllText(@"test.txt").Trim();
    string var = "test";
    if (Convert.ToDouble(tfile) > Convert.ToDouble(var))
    {
    }
    else if (Convert.ToDouble(tfile) < Convert.ToDouble(var))
    {
    }
    else //Equal
    {
    }
    Maybe you want to use a TryParse to avoid throwing exceptions too?
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - 2018)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2011
    Posts
    115

    Re: Check if string has bigger value

    Quote Originally Posted by AceInfinity View Post
    Code:
    string tfile = System.IO.File.ReadAllText(@"test.txt").Trim();
    string var = "test";
    if (Convert.ToDouble(tfile) > Convert.ToDouble(var))
    {
    }
    else if (Convert.ToDouble(tfile) < Convert.ToDouble(var))
    {
    }
    else //Equal
    {
    }
    Maybe you want to use a TryParse to avoid throwing exceptions too?
    thanks for reply, I chouldnt write exactly what I wont I guess, this way we can compare maybee all the indeks of test file.
    What I really need to be checked is only the one value from my groupcollection in the function : *Value \(([^\)]+)\)[^-] <<< this one


    coz the output in text file looks like this :

    Congratulation : username :::...Score...::: 230.78 ...::istance Meters...::: 234.45

    I need to check only for the Score if it is bigger or not.

  4. #4
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Check if string has bigger value

    score is bigger than what though? I don't know what you're entire text file looks like, you have some regex which parses a collection of data, and that's about all I know at this point.
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - 2018)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width