6 Replies - 551 Views - Last Post: 18 April 2012 - 03:27 AM Rate Topic: -----

#1 montaha988  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 04-April 12

Help in parsing

Posted 04 April 2012 - 04:09 AM

Hi all,

I have a file which contains lines like the following :

Line 1: Pass 2/2 frame 5465/5749 15574295B 51.462 50.234 55.344 56.937 210F
Line 2: Pass 2/2 frame 5452/5735 15571353B 51.466 50.235 55.330 57.012 116F 344F
Line 3: Pass 2/2 frame 5495/5782 15593147B 39.195 37.675 45.782 48.996 787F37.495 35.928 45.071 48.092 811F38.408 36.913 44.433 48.123 852F37.102 35.567 43.789 47.557 869F36.774 35.246 43.322 47.165 914F37.376 35.886 43.465 46.688 990F36.663 35.126 43.528 46.879 979F37.688 36.253 42.631 47.142 943F38.459 37.118 42.163 47.445 903F38.254 36.992 40.945 47.740 843F44.970 45.302 41.549 55.175 3039F41.745 40.885 41.478 53.953 613F40.146 38.934 41.952 52.936 606F39.142 38.497 37.875 55.957 389F46.844 45.352 52.002 59.382 177F

I wanna the value before the "F" char ,if line contains 2F it will sum the two values and so on ( at least I wanna skip the line that contains more than 2F )

the following code work when the line has 2F but it is not work with the third line


char[] sep = new char[] { ' ' };
           while ((line = reader.ReadLine()) != null)
           {
               string[] items = line.Split(sep);
               foreach (string item in items)
               {
                  
                   Match match = Regex.Match(item, @"\dF\d");
                   if (match.Success)
                   {
                       string[] fff = Regex.Split(item, "F");
                       foreach (string f in fff)
                       {
                           sw.WriteLine(f);
                           break;
                       }
                     
                   }
                   string[] items2 =item.Split(sep);
                   
                   foreach (string item2 in items2)
                   {
                       
                       if (item2.EndsWith("F"))
                       {
                           F++;
                           Framesize = item2.Replace('F', ' ');
                           if (F == 1) temp = Convert.ToInt32(Framesize);

                               if (F == 2)
                               {

                                   temp = temp + Convert.ToInt32(Framesize);
                                   Framesize = temp.ToString();
                                   flag = 1;

                               }

                           
                       }
  

                   }//end foreach
                   

               }
               if (F==1 || F==2 )
                   sw.WriteLine(Framesize);
               F = 0;
              flag = 0;

           }
           sw.Close();}



is there any help ???!!!!!

Is This A Good Question/Topic? 0
  • +

Replies To: Help in parsing

#2 tlhIn`toq  Icon User is offline

  • Closing in on 5,000
  • member icon

Reputation: 4928
  • View blog
  • Posts: 10,465
  • Joined: 02-June 10

Re: Help in parsing

Posted 04 April 2012 - 08:31 AM

Personally I would split the line on the space character. That gives you an array.
Loop through that returned array
Get the .IndexOf('F')
You value is therefore everything from 0 to the index you just got.

Should be about 5 lines.
Was This Post Helpful? 1
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 1953
  • View blog
  • Posts: 8,685
  • Joined: 29-May 08

Re: Help in parsing

Posted 04 April 2012 - 01:47 PM

I would possibly use a regex to match Space Digit+ Letter(F)
Then do a foreach over each line, if the rexeg has 0 or more than 3 then continue to the next iteration.
Otherwise get total for all the matched numbers after conversion to numeric type.
Was This Post Helpful? 0
  • +
  • -

#4 montaha988  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 04-April 12

Re: Help in parsing

Posted 09 April 2012 - 11:31 PM

thanks all,
I tried to match on (@"\dF\t\d")
and it skip the last line but get the final value in it which is match with the REGEX (177F)
how do I delete this last line?

by the way I have just started C# :helpsmilie:
Was This Post Helpful? 0
  • +
  • -

#5 montaha988  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 04-April 12

Re: Help in parsing

Posted 17 April 2012 - 05:01 AM

thanks everybody
I have solved the problem :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#6 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1211
  • View blog
  • Posts: 4,128
  • Joined: 27-January 10

Re: Help in parsing

Posted 17 April 2012 - 08:37 AM

You should post your code so others can see your solution in case Google leads somebody here. :)
Was This Post Helpful? 0
  • +
  • -

#7 montaha988  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 04-April 12

Re: Help in parsing

Posted 18 April 2012 - 03:27 AM

Ok ,
I used a regex (@"\dF\t\d") to match to skip the last line
but it will get last value in it
so I opened the file again in read all lines then write all line again except last line which has the last value in last line in the original file :bigsmile:
maybe you don't like my way but what important to me it works fine
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1