473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How To Parse A Data File?

I am just learning to code in C# and need to parse a file that is in the following format:

[VOR]
YMS 114.500 N044.08.35.400 W080.08.46.200
YTP 116.550 N043.40.18.00 W079.39.51.000
YWT 115.000 N043.27.31.200 W080.22.45.600
YSO 117.350 N044.14.19.200 W079.10.30.000
YYZ 112.150 N043.39.28.800 W079.37.54.000

[NDB]
OO 391 N043.55.18.000 W078.54.18.000
KZ 248 N043.56.01.000 W079.19.44.999
TZ 257 N043.36.46.000 W079.23.07.999
ZDH 385 N043.44.17.000 W079.34.11.000
ZLP 341 N043.37.41.000 W079.43.55.000
ZTO 403.000 N043.44.19.671 W079.42.09.868
ZYZ 368.000 N043.37.10.222 W079.32.56.396

[Next Section]
....

The amount of data in each section is different in every file.

I need a way to get data from one section at a time. I know how to read and split the lines but cant seem to figure out how to only grab data from one section.

Any help would be great.
Thanks
Mar 4 '10 #1
7 1663
ThatThatGuy
449 Expert 256MB
search for the line which contains ' [ ' and ' ] ' then start a new reading process
Mar 4 '10 #2
tlhintoq
3,525 Expert 2GB
Or search for the blank line between the blocks
Mar 4 '10 #3
So I have decided to parse the entire file using 2 passes.
The first pass it to get the number of data fields in each section and the second pass will actually populate the data into their respective arrays.

here is the code for the first pass:

Expand|Select|Wrap|Line Numbers
  1. public void OpenSector(string strFile)
  2.         {
  3.             if (File.Exists(strFile))
  4.             {
  5.                 using (StreamReader re = File.OpenText(strFile))
  6.                 {
  7.                     int lines=0;//For Line Counting
  8.                     int comments = 0;//Counts Comment Lines
  9.                     int blanks = 0;//Counts Blank Lines
  10.                     int sectioncount = 0;//Counts Sections In Sector "[...]"
  11.                     int colorcount = 0;//Counts Color Definitions #define AQUA 16776960
  12.                     int infocount = 0;//Counts Info Lines
  13.                     int airportcount = 0;//Counts Airports
  14.                     int runwaycount = 0;//Counts Runsways
  15.                     int vorcount = 0;//Counts VORs
  16.                     int ndbcount = 0;//Counts NDBs
  17.                     int fixcount = 0;//Counts Fixes
  18.                     int labelcount = 0;//Counts Labels
  19.                     int lowairwaycount = 0;//Counts Low Airways
  20.                     int highairwaycount = 0;//Counts High Airways
  21.                     int geocount = 0;//Counts Geo Data
  22.                     int artcclow = 0;//Counts artcc lower boundries
  23.                     int artcchigh = 0;//Counts artcc high boundries
  24.                     int starcount = 0;//Counts Stars
  25.                     int sidcount = 0;//Counts Sids
  26.  
  27.                     String input;
  28.                     string section = "";
  29.  
  30.                     while ((input=re.ReadLine())!=null) 
  31.                     {
  32.                         lines = lines + 1;
  33.                         if (input == "")
  34.                         {
  35.                             blanks = blanks + 1;
  36.                         }
  37.                         else if (input.Substring(0, 1) == ";")
  38.                         {
  39.                             //Is a comment
  40.                             comments = comments + 1;
  41.                         }
  42.                         else if (input.Substring(0, 1) == "#")
  43.                         {
  44.                             //Is a comment
  45.                             colorcount = colorcount + 1;
  46.                         }
  47.                         else if (input.Substring(0, 1) == "[")
  48.                         {
  49.                             sectioncount = sectioncount + 1;
  50.                             section = input.Substring(0, input.IndexOf("]") + 1);
  51.                         }
  52.                         else
  53.                         {
  54.                             switch (section.ToUpper())
  55.                             {
  56.                                 case "[INFO]":
  57.                                     infocount = infocount + 1;
  58.                                     break;
  59.                                 case "[AIRPORT]":
  60.                                     airportcount = airportcount + 1;
  61.                                     break;
  62.                                 case "[RUNWAY]":
  63.                                     runwaycount = runwaycount + 1;
  64.                                     break;
  65.                                 case "[VOR]":
  66.                                     vorcount = vorcount + 1;
  67.                                     break;
  68.                                 case "[NDB]":
  69.                                     ndbcount = ndbcount + 1;
  70.                                     break;
  71.                                 case "[FIXES]":
  72.                                     fixcount = fixcount + 1;
  73.                                     break;
  74.                                 case "[LABELS]":
  75.                                     labelcount = labelcount + 1;
  76.                                     break;
  77.                                 case "[LOW AIRWAY]":
  78.                                     lowairwaycount = lowairwaycount + 1;
  79.                                     break;
  80.                                 case "[HIGH AIRWAY]":
  81.                                     highairwaycount = highairwaycount + 1;
  82.                                     break;
  83.                                 case "[GEO]":
  84.                                     geocount = geocount + 1;
  85.                                     break;
  86.                                 case "[ARTCC LOW]":
  87.  
  88.                                     artcclow = artcclow + 1;
  89.                                     break;
  90.                                 case "[ARTCC HIGH]":
  91.  
  92.                                     artcchigh = artcchigh + 1;
  93.                                     break;
  94.                                 case "[STAR]":
  95.  
  96.                                     starcount = starcount + 1;
  97.                                     break;
  98.                                 case "[SID]":
  99.  
  100.                                     sidcount = sidcount + 1;
  101.                                     break;
  102.                             }
  103.                         }
  104.                     }
  105.  
  106.                     //Reading Done
  107.                     re.Close();//Close Stream Reader
  108. }
Mar 4 '10 #4
tlhintoq
3,525 Expert 2GB
By defining all your variables within the method none of them available one the method completes and returns.

You aren't doing anything within the method with the counts.
So what happens next? It is almost as if all this processing gets thrown away.
Mar 4 '10 #5
as of right now the method does nothing but count the amount of data in each section.
i am currently writing the second pass of the file where i will setup array for all the data. I am simple using all the count values to define the array size. The arrays will return the data to the main form.

string[] strInfo = new string[infocount];

i will post the second pass once i have it written

:D
Mar 4 '10 #6
Here is the final class. It calculates how many data fields in each section. (completed in the first pass). Then puts the data into the appropriate public string arrays.(completed in the second pass)

Expand|Select|Wrap|Line Numbers
  1.   class SectorFileParser
  2.     {
  3.         //Declare Sector File Data Arrays
  4.         public string[] strColorName,strColorValue,strInfo;
  5.         public string[] strAirportID, strAirportFreq, strAirportLat, strAirportLon, strAirportClass;
  6.         public string[] strRunwayID, strRunwayHeadings, strRunwayStartLat, strRunwayStartLon, strRunwayEndLat, strRunwayEndLon;
  7.         public string[] strVorID, strVorFreq, strVorLat, strVorLon;
  8.         public string[] strNDBID, strNDBFreq, strNDBLat, strNDBLon;
  9.         public string[] strFixID, strFixLat, strFixLon;
  10.         public string[] strLabelID, strLabelLat, strLabelLon, strLabelColor;
  11.         public string[] strLowAirwayID, strLowAirwayStartLat, strLowAirwayStartLon, strLowAirwayEndLat, strLowAirwayEndLon;
  12.         public string[] strHighAirwayID, strHighAirwayStartLat, strHighAirwayStartLon, strHighAirwayEndLat, strHighAirwayEndLon;
  13.         public string[] strGeoStartLat, strGeoStartLon, strGeoEndLat, strGeoEndLon, strGeoColor;
  14.         public string[] strArtccLowID, strArtccLowStartLat, strArtccLowStartLon, strArtccLowEndLat, strArtccLowEndLon;
  15.         public string[] strArtccHighID, strArtccHighStartLat, strArtccHighStartLon, strArtccHighEndLat, strArtccHighEndLon;
  16.         public string[] strStarID, strStarStartLat, strStarStartLon, strStarEndLat, strStarEndLon ,strStarColor ;
  17.         public string[] strSIDID, strSIDStartLat, strSIDStartLon, strSIDEndLat, strSIDEndLon, strSIDColor;
  18.  
  19.         public void OpenSector(string strFile)
  20.         {
  21.             if (File.Exists(strFile))
  22.             {
  23.                //Start Pass 1
  24.                 using (StreamReader re = File.OpenText(strFile))
  25.                 {
  26.                     int lines=0;//For Line Counting
  27.                     int comments = 0;//Counts Comment Lines
  28.                     int blanks = 0;//Counts Blank Lines
  29.                     int sectioncount = 0;//Counts Sections In Sector "[...]"
  30.                     int colorcount = 0;//Counts Color Definitions #define AQUA 16776960
  31.                     int infocount = 0;//Counts Info Lines
  32.                     int airportcount = 0;//Counts Airports
  33.                     int runwaycount = 0;//Counts Runsways
  34.                     int vorcount = 0;//Counts VORs
  35.                     int ndbcount = 0;//Counts NDBs
  36.                     int fixcount = 0;//Counts Fixes
  37.                     int labelcount = 0;//Counts Labels
  38.                     int lowairwaycount = 0;//Counts Low Airways
  39.                     int highairwaycount = 0;//Counts High Airways
  40.                     int geocount = 0;//Counts Geo Data
  41.                     int artcclow = 0;//Counts artcc lower boundries
  42.                     int artcchigh = 0;//Counts artcc high boundries
  43.                     int starcount = 0;//Counts Stars
  44.                     int sidcount = 0;//Counts Sids
  45.  
  46.                     String input;
  47.                     string section = "";
  48.  
  49.                     while ((input=re.ReadLine())!=null) 
  50.                     {
  51.                         lines = lines + 1;
  52.                         if (input == "")
  53.                         {
  54.                             blanks = blanks + 1;
  55.                         }
  56.                         else if (input.Substring(0, 1) == ";")
  57.                         {
  58.                             //Is a comment
  59.                             comments = comments + 1;
  60.                         }
  61.                         else if (input.Substring(0, 1) == "#")
  62.                         {
  63.                             //Is a comment
  64.                             colorcount = colorcount + 1;
  65.                         }
  66.                         else if (input.Substring(0, 1) == "[")
  67.                         {
  68.                             sectioncount = sectioncount + 1;
  69.                             section = input.Substring(0, input.IndexOf("]") + 1);
  70.                         }
  71.                         else
  72.                         {
  73.                             switch (section.ToUpper())
  74.                             {
  75.                                 case "[INFO]":
  76.                                     infocount = infocount + 1;
  77.                                     break;
  78.                                 case "[AIRPORT]":
  79.                                     airportcount = airportcount + 1;
  80.                                     break;
  81.                                 case "[RUNWAY]":
  82.                                     runwaycount = runwaycount + 1;
  83.                                     break;
  84.                                 case "[VOR]":
  85.                                     vorcount = vorcount + 1;
  86.                                     break;
  87.                                 case "[NDB]":
  88.                                     ndbcount = ndbcount + 1;
  89.                                     break;
  90.                                 case "[FIXES]":
  91.                                     fixcount = fixcount + 1;
  92.                                     break;
  93.                                 case "[LABELS]":
  94.                                     labelcount = labelcount + 1;
  95.                                     break;
  96.                                 case "[LOW AIRWAY]":
  97.                                     lowairwaycount = lowairwaycount + 1;
  98.                                     break;
  99.                                 case "[HIGH AIRWAY]":
  100.                                     highairwaycount = highairwaycount + 1;
  101.                                     break;
  102.                                 case "[GEO]":
  103.                                     geocount = geocount + 1;
  104.                                     break;
  105.                                 case "[ARTCC LOW]":
  106.                                     //Identify Names Here To Get Accurate Count
  107.                                     artcclow = artcclow + 1;
  108.                                     break;
  109.                                 case "[ARTCC HIGH]":
  110.                                     //Identify Names Here To Get Accurate Count
  111.                                     artcchigh = artcchigh + 1;
  112.                                     break;
  113.                                 case "[STAR]":
  114.                                     //Identify Names Here To Get Accurate Count
  115.                                     starcount = starcount + 1;
  116.                                     break;
  117.                                 case "[SID]":
  118.                                     //Identify Names Here To Get Accurate Count
  119.                                     sidcount = sidcount + 1;
  120.                                     break;
  121.                             }
  122.                         }
  123.                     }
  124.  
  125.                     //Pass 1 Complete
  126.                     re.Close();//Close Stream Reader
  127.  
  128.  
  129.                     //Start Pass 2
  130.  
  131.                     //Setup Color Arrays
  132.                     int tempcolor = -1;
  133.                     strColorName  = new string[colorcount];
  134.                     strColorValue = new string[colorcount];
  135.  
  136.                     //Setup Info Array
  137.                     int tempinfo = -1;
  138.                     strInfo = new string[infocount];
  139.  
  140.                     //Setup Runaway Arrays
  141.                     int temprunways = -1;
  142.                     strRunwayID = new string[runwaycount];
  143.                     strRunwayHeadings = new string[runwaycount];
  144.                     strRunwayStartLat = new string[runwaycount];
  145.                     strRunwayStartLon = new string[runwaycount];
  146.                     strRunwayEndLat = new string[runwaycount];
  147.                     strRunwayEndLon = new string[runwaycount];
  148.  
  149.                     //Setup Airport Arrays
  150.                     int tempairport = -1;
  151.                     strAirportID = new string[airportcount];
  152.                     strAirportFreq = new string[airportcount];
  153.                     strAirportLat = new string[airportcount];
  154.                     strAirportLon = new string[airportcount];
  155.                     strAirportClass = new string[airportcount];
  156.  
  157.                     //Setup VOR Arrays
  158.                     int tempVor = -1;
  159.                     strVorID = new string[vorcount];
  160.                     strVorFreq = new string[vorcount];
  161.                     strVorLat = new string[vorcount];
  162.                     strVorLon = new string[vorcount];
  163.  
  164.                     //Setup NDB Arrays
  165.                     int tempNDB = -1;
  166.                     strNDBID = new string[ndbcount];
  167.                     strNDBFreq = new string[ndbcount];
  168.                     strNDBLat = new string[ndbcount];
  169.                     strNDBLon = new string[ndbcount];
  170.  
  171.                     //Setup Fix Arrays
  172.                     int tempFix = -1;
  173.                     strFixID = new string[fixcount];
  174.                     strFixLat = new string[fixcount];
  175.                     strFixLon = new string[fixcount];
  176.  
  177.                     //Setup Label Arrays
  178.                     int tempLabel = -1;
  179.                     strLabelID=new string[labelcount];
  180.                     strLabelLat = new string[labelcount];
  181.                     strLabelLon = new string[labelcount];
  182.                     strLabelColor = new string[labelcount]; 
  183.  
  184.                     //Setup Low Airway Arrays
  185.                     int tempLowAirways = -1;
  186.                     strLowAirwayID = new string[lowairwaycount];
  187.                     strLowAirwayStartLat = new string[lowairwaycount];
  188.                     strLowAirwayStartLon = new string[lowairwaycount];
  189.                     strLowAirwayEndLat = new string[lowairwaycount];
  190.                     strLowAirwayEndLon = new string[lowairwaycount];
  191.  
  192.                     //Setup High Airway Arrays
  193.                     int tempHighAirways = -1;
  194.                     strHighAirwayID = new string[highairwaycount];
  195.                     strHighAirwayStartLat = new string[highairwaycount];
  196.                     strHighAirwayStartLon = new string[highairwaycount];
  197.                     strHighAirwayEndLat = new string[highairwaycount];
  198.                     strHighAirwayEndLon = new string[highairwaycount];
  199.  
  200.                     //Setup Geo Data Arrays
  201.                     int tempGeo = -1;
  202.                     strGeoStartLat = new string[geocount];
  203.                     strGeoStartLon = new string[geocount];
  204.                     strGeoEndLat = new string[geocount];
  205.                     strGeoEndLon = new string[geocount];
  206.                     strGeoColor = new string[geocount];
  207.  
  208.                     //Setup Low ARTCC Arrays
  209.                     int tempARTCCLow = -1;
  210.                     strArtccLowID = new string[artcclow];
  211.                     strArtccLowStartLat = new string[artcclow];
  212.                     strArtccLowStartLon = new string[artcclow];
  213.                     strArtccLowEndLat = new string[artcclow];
  214.                     strArtccLowEndLon = new string[artcclow];
  215.  
  216.                     //Setup High ARTCC Arrays
  217.                     int tempARTCCHigh = -1;
  218.                     strArtccHighID = new string[artcchigh];
  219.                     strArtccHighStartLat = new string[artcchigh];
  220.                     strArtccHighStartLon = new string[artcchigh];
  221.                     strArtccHighEndLat = new string[artcchigh];
  222.                     strArtccHighEndLon = new string[artcchigh];
  223.  
  224.                     //Setup Star Arrays
  225.                     int tempStar = -1;
  226.                     strStarID=new string[starcount];
  227.                     strStarStartLat = new string[starcount];
  228.                     strStarStartLon = new string[starcount];
  229.                     strStarEndLat = new string[starcount];
  230.                     strStarEndLon = new string[starcount];
  231.                     strStarColor = new string[starcount];
  232.  
  233.                     //Setup Sid Arrays
  234.                     int tempSid = -1;
  235.                     strSIDID = new string[sidcount];
  236.                     strSIDStartLat = new string[sidcount];
  237.                     strSIDStartLon = new string[sidcount];
  238.                     strSIDEndLat = new string[sidcount];
  239.                     strSIDEndLon = new string[sidcount];
  240.                     strSIDColor = new string[sidcount];
  241.  
  242.                     //Read The Data
  243.                     using (StreamReader re2 = File.OpenText(strFile))
  244.                     {
  245.                         while ((input = re2.ReadLine()) != null)
  246.                         {
  247.  
  248.                             if (input == "")
  249.                             {
  250.                                //Blank Line So Ignore It
  251.                             }
  252.                             else if (input.Substring(0, 1) == ";")
  253.                             {
  254.                                 //Is a comment so Ignore it
  255.  
  256.                             }
  257.                             else if (input.Substring(0, 1) == "#")
  258.                             {
  259.                                 //Load Colors Into Array
  260.                                 tempcolor = tempcolor + 1;
  261.                                 string[] parsedcolor = input.Split(new Char [] {' '});
  262.                                 strColorName[tempcolor] = parsedcolor[1];
  263.                                 strColorValue[tempcolor] = parsedcolor[2];
  264.                             }
  265.                             else if (input.Substring(0, 1) == "[")
  266.                             {
  267.                                 sectioncount = sectioncount + 1;
  268.                                 section = input.Substring(0, input.IndexOf("]") + 1);
  269.                             }
  270.                             else
  271.                             {
  272.                                 //Steralize Comments Off Ends Of Data 
  273.                                 if (input.IndexOf(";") > 0)
  274.                                 {
  275.                                     input = input.Substring(0, input.IndexOf(";" ));
  276.                                 }
  277.                                 switch (section.ToUpper())
  278.                                 {
  279.                                     case "[INFO]":
  280.                                         tempinfo = tempinfo + 1;
  281.                                         strInfo[tempinfo] = input;
  282.                                         break;
  283.                                     case "[AIRPORT]":
  284.                                         tempairport = tempairport + 1;
  285.                                         string[] parsedairport = input.Split(new Char[] { ' ' });
  286.                                         strAirportID[tempairport] = parsedairport[0];
  287.                                         strAirportFreq[tempairport] = parsedairport[1];
  288.                                         strAirportLat[tempairport] = parsedairport[2];
  289.                                         strAirportLon[tempairport] = parsedairport[3];
  290.                                         strAirportClass[tempairport] = parsedairport[4];
  291.                                         break;
  292.                                     case "[RUNWAY]":
  293.                                         temprunways = temprunways + 1;
  294.                                         string[] parsedrunways = input.Split(new Char[] { ' ' });
  295.                                         strRunwayID[temprunways] = parsedrunways[0] + "/" + parsedrunways[1];
  296.                                         strRunwayHeadings[temprunways] = parsedrunways[2] + "/" + parsedrunways[3];
  297.                                         strRunwayStartLat[temprunways] = parsedrunways[4];
  298.                                         strRunwayStartLon[temprunways] = parsedrunways[5];
  299.                                         strRunwayEndLat[temprunways] = parsedrunways[6];
  300.                                         strRunwayEndLon[temprunways] = parsedrunways[7];
  301.                                         break;
  302.                                     case "[VOR]":
  303.                                         tempVor = tempVor + 1;
  304.                                         string[] parsedVORs = input.Split(new Char[] { ' ' });
  305.                                         strVorID[tempVor] = parsedVORs[0];
  306.                                         strVorFreq[tempVor] = parsedVORs[1];
  307.                                         strVorLat[tempVor] = parsedVORs[2];
  308.                                         strVorLon[tempVor] = parsedVORs[3];
  309.                                         break;
  310.                                     case "[NDB]":
  311.                                         tempNDB = tempNDB + 1;
  312.                                         string[] parsedNDBs = input.Split(new Char[] { ' ' });
  313.                                         strNDBID[tempNDB] = parsedNDBs[0];
  314.                                         strNDBFreq[tempNDB] = parsedNDBs[1];
  315.                                         strNDBLat[tempNDB] = parsedNDBs[2];
  316.                                         strNDBLon[tempNDB] = parsedNDBs[3];
  317.                                         break;
  318.                                     case "[FIXES]":
  319.                                         tempFix = tempFix + 1;
  320.                                         string[] parsedfix=input.Split(new Char[] { ' ' });
  321.                                         strFixID[tempFix] = parsedfix[0];
  322.                                         strFixLat[tempFix] = parsedfix[1];
  323.                                         strFixLon[tempFix] = parsedfix[2];
  324.                                         break;
  325.                                     case "[LABELS]":
  326.                                         tempLabel = tempLabel + 1;
  327.                                         string[] parsedLabel = input.Split(new Char[] { ' ' });
  328.                                         strLabelID[tempLabel] = parsedLabel[0].Substring(1, parsedLabel[0].Length - 2);
  329.                                         strLabelLat[tempLabel] = parsedLabel[1];
  330.                                         strLabelLon[tempLabel] = parsedLabel[2];
  331.                                         strLabelColor[tempLabel] = parsedLabel[3];
  332.                                         break;
  333.                                     case "[LOW AIRWAY]":
  334.                                         tempLowAirways = tempLowAirways + 1;
  335.                                         string[] parsedLowAirways= input.Split(new Char[] { ' ' });
  336.                                         strLowAirwayID[tempLowAirways] = parsedLowAirways[0];
  337.                                         strLowAirwayStartLat[tempLowAirways] = parsedLowAirways[1];
  338.                                         strLowAirwayStartLon[tempLowAirways] = parsedLowAirways[2];
  339.                                         strLowAirwayEndLat[tempLowAirways] = parsedLowAirways[3];
  340.                                         strLowAirwayEndLon[tempLowAirways] = parsedLowAirways[4];
  341.                                         break;
  342.                                     case "[HIGH AIRWAY]":
  343.                                         tempHighAirways = tempHighAirways + 1;
  344.                                         string[] parsedHighAirways= input.Split(new Char[] { ' ' });
  345.                                         strHighAirwayID[tempHighAirways] = parsedHighAirways[0];
  346.                                         strHighAirwayStartLat[tempHighAirways] = parsedHighAirways[1];
  347.                                         strHighAirwayStartLon[tempHighAirways] = parsedHighAirways[2];
  348.                                         strHighAirwayEndLat[tempHighAirways] = parsedHighAirways[3];
  349.                                         strHighAirwayEndLon[tempHighAirways] = parsedHighAirways[4];
  350.                                         break;
  351.                                     case "[GEO]":
  352.                                         tempGeo = tempGeo + 1;
  353.                                         string[] parsedGeo = input.Split(new Char[] { ' ' });
  354.                                         strGeoStartLat[tempGeo] = parsedGeo[0];
  355.                                         strGeoStartLon[tempGeo] = parsedGeo[1];
  356.                                         strGeoEndLat[tempGeo] = parsedGeo[2];
  357.                                         strGeoEndLon[tempGeo] = parsedGeo[3];
  358.                                         strGeoColor[tempGeo] = parsedGeo[4];
  359.                                         break;
  360.                                     case "[ARTCC LOW]":
  361.                                         tempARTCCLow = tempARTCCLow + 1;
  362.                                         string[] parsedARTCCLow = input.Split(new Char[] { ' ' });
  363.                                         strArtccLowID[tempARTCCLow] = parsedARTCCLow[0];
  364.                                         strArtccLowStartLat[tempARTCCLow] = parsedARTCCLow[1];
  365.                                         strArtccLowStartLon[tempARTCCLow] = parsedARTCCLow[2];
  366.                                         strArtccLowEndLat[tempARTCCLow] = parsedARTCCLow[3];
  367.                                         strArtccLowEndLon[tempARTCCLow] = parsedARTCCLow[4];
  368.                                         break;
  369.                                     case "[ARTCC HIGH]":
  370.                                         tempARTCCHigh = tempARTCCHigh + 1;
  371.                                         string[] parsedARTCCHigh = input.Split(new Char[] { ' ' });
  372.                                         strArtccHighID[tempARTCCHigh] = parsedARTCCHigh[0];
  373.                                         strArtccHighStartLat[tempARTCCHigh] = parsedARTCCHigh[1];
  374.                                         strArtccHighStartLon[tempARTCCHigh] = parsedARTCCHigh[2];
  375.                                         strArtccHighEndLat[tempARTCCHigh] = parsedARTCCHigh[3];
  376.                                         strArtccHighEndLon[tempARTCCHigh] = parsedARTCCHigh[4];
  377.                                         break;
  378.                                     case "[STAR]":
  379.                                         tempStar = tempStar + 1;
  380.                                         strStarID[tempStar] = input.Substring(0, 26);
  381.                                         string[] parsedStars = input.Substring(26).Split(new Char[] { ' ' });
  382.                                         strStarStartLat[tempStar] = parsedStars[0];
  383.                                         strStarStartLon[tempStar] = parsedStars[1];
  384.                                         strStarEndLat[tempStar] = parsedStars[2];
  385.                                         strStarEndLon[tempStar] = parsedStars[3];
  386.                                         try
  387.                                         {
  388.                                             strStarColor[tempStar] = parsedStars[4];
  389.                                         }
  390.                                         catch //If No Color Provided....
  391.                                         {
  392.                                             strStarColor[tempStar] = "";
  393.                                         }
  394.                                         break;
  395.                                     case "[SID]":
  396.                                         tempSid = tempSid + 1;
  397.                                         strSIDID[tempSid] = input.Substring(0, 26);
  398.                                         string[] parsedSIDs = input.Substring(26).Split(new Char[] { ' ' });
  399.                                         strSIDStartLat[tempSid] = parsedSIDs[0];
  400.                                         strSIDStartLon[tempSid] = parsedSIDs[1];
  401.                                         strSIDEndLat[tempSid] = parsedSIDs[2];
  402.                                         strSIDEndLon[tempSid] = parsedSIDs[3];
  403.                                         try
  404.                                         {
  405.                                             strSIDColor[tempSid] = parsedSIDs[4];
  406.                                         }
  407.                                         catch //If No Color Provided....
  408.                                         {
  409.                                             strSIDColor[tempSid] = "";
  410.                                         }
  411.                                             break;
  412.                                 }
  413.                             }
  414.                         }
  415.  
  416.                         //Reading Done
  417.                         re2.Close();//Close Stream Reader
  418.                     }
  419.  
  420.  
  421.  
  422.  
  423.                 }
  424.             }
  425.             else
  426.             {
  427.                 //File Not Found
  428.             }
  429.  
  430.         }
  431.  
  432.  
Mar 5 '10 #7
GaryTexmo
1,501 Expert 1GB
Here's a few tips to help you compact your code down...

1) You can use the generic List class instead of string arrays so you don't need to do the count. Define a list and add to it as such...
Expand|Select|Wrap|Line Numbers
  1. List<string> myList = new List<string>();
  2. myList.Add("a string!");
Other than that, they work just like arrays.

2) Use hash tables to eliminate your switch statement... a hash table has a key and an object. For example, you could do the following...

Expand|Select|Wrap|Line Numbers
  1. Hashtable sectionHash = new Hashtable();
  2. string section = ... (however you get it here);
  3.  
  4. if (!sectionHash.ContainsKey(section))
  5.   sectionHash[section] = new List<string>();
  6.  
  7. sectionHash[section].Add(... whatever ...);
Since you've got quite a bit of stuff to add here, you could even put it all in a struct so you don't need to keep so many arrays.

---------------------

Just some ideas, hopefully they're of use to you.
Mar 5 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: chuck amadi | last post by:
Hi , Im trying to parse a specific users mailbox (testwwws) and output the body of the messages to a file ,that file will then be loaded into a PostGresql DB at some point . I have read the...
1
by: chuck amadi | last post by:
By the way list is there a better way than using the readlines() to > > >parse the mail data into a file , because Im using > > >email.message_from_file it returns > > >all the data i.e reads one...
6
by: nate | last post by:
Hello, Does anyone know where I can find an ASP server side script written in JavaScript to parse text fields from a form method='POST' using enctype='multipart/form-data'? I'd also like it to...
19
by: Johnny Google | last post by:
Here is an example of the type of data from a file I will have: Apple,4322,3435,4653,6543,4652 Banana,6934,5423,6753,6531 Carrot,3454,4534,3434,1111,9120,5453 Cheese,4411,5522,6622,6641 The...
13
by: DH | last post by:
Hi, I'm trying to strip the html and other useless junk from a html page.. Id like to create something like an automated text editor, where it takes the keywords from a txt file and removes them...
6
by: trevor | last post by:
Incorrect values when using float.Parse(string) I have discovered a problem with float.Parse(string) not getting values exactly correct in some circumstances(CSV file source) but in very similar...
5
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming. FYI Although I have called...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
6
by: =?Utf-8?B?RGF2aWRN?= | last post by:
Hello, I have an XML file generated from a third party application that I would like to parse. Ideally, I plan on having a windows service setup to scan various folders for XML files and parse the...
5
by: goldtech | last post by:
SAX XML Parse Python error message Hi, My first attempt at SAX, but have an error message I need help with. I cite the error message, code, and xml below. Be grateful if anyone can tell me...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.