Results 1 to 4 of 4

Thread: Liststring more then 1 variable

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2011
    Posts
    115

    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.
    Last edited by deve; Apr 16th, 2012 at 09:56 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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"))
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2011
    Posts
    115

    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

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

    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.
    <<<------------
    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