-
Apr 27th, 2012, 04:03 AM
#1
Thread Starter
Lively Member
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..
-
Apr 29th, 2012, 12:07 AM
#2
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?
<<<------------
.NET Programming (2012 - 2018)
®Crestron - DMC-T Certified Programmer | Software Developer <<<------------
-
Apr 29th, 2012, 03:07 AM
#3
Thread Starter
Lively Member
Re: Check if string has bigger value
Originally Posted by AceInfinity
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.
-
Apr 29th, 2012, 10:03 PM
#4
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.
<<<------------
.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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|