Liststring more then 1 variable
I wont to grab few lines from a text in to my textbox and chould not figure out on how to do it with when there is more then one line to take.
For example my text includes this lines :
PHP Code:
Location : Utah
Season : Pre-Rut
Time : 04/13/12 19:42:18
Duration : 15 minutes
Game type : Best_Trophy
Difficulty: Expert
Result : Game_has_a_winner!
Players : 2
1. "Brian" is a Winner!
Trophy(ies) : 4
Score : 428.747
Best Trophy : Male Whitetail
Points : Total (428.747) = Animal score (150.010)
Distance : 246.07 meters
2. "stefano sorsoli
Now I need to have :
Location : + Time : + Animal score in one line on my textbox .
I used this :
Code:
List<string> data = new List<string>();
using (StreamReader sr = new StreamReader(textBox1.Text + @"\Game\Game.LOG"))
{
while (sr.Peek() > -1)
{
string ln = sr.ReadLine();
if (ln.Contains("Location :")) + (" Time :")) + (" Animal score ")
{
string values = (from Match m in Regex.Matches(ln, @"""(.*?)""", RegexOptions.IgnoreCase)
select m.Value).ToArray()[0];
textBox3.Text = ("All Time Winner is : " + values.Replace((char)34, '\n'));
}
}
}
but this doesnt work.
Re: Liststring more then 1 variable
This line doesn't make any sense:
Code:
if (ln.Contains("Location :")) + (" Time :")) + (" Animal score ")
I assume what you actually want is to keep the line if it starts with "Location" or it starts with "Time" or it contains "Animal score".
Code:
if (ln.StartsWith("Location") || ln.StartsWith("Time") || ln.Contains("Animal score"))
Re: Liststring more then 1 variable
I wont to keep the line Location : and Time : then on animal score I just wont to keep the value : 150.010
Re: Liststring more then 1 variable
1. Check if the line contains "Location" or "Time" or "Animal score" and also check for ":"
2. Split by ":" char and return the Trimmed version of the second index of that split array to get your value, add it to your "container" variable which collects that result
3. When done, display what you've retrieved from your "container" variable
If you're still struggling i'll help you out. I'm sure jmcilhinney is well capable of it as well. He's corrected that line of code for you which should be a step in the right direction for what you're trying to do here.