Hello. I am beginner.
Firstly, I'd like to start reading from this line as follow to end of the file:
1 START OF RMS MAP
Than, I'd like to write specific line to text file.
I haven't succeeded in the first step.
Parent Directory: ftp://cddis.gsfc.nasa.gov/gnss/products/ionex/2017/
All files begin with codg.
I have 365 files beginning with codg.
What I have tried:
Regular Expression for this line: (s, @"^\s*1\s+START OF RMS MAP\S*$")
using System;
using System.IO;
namespace ReadFromFile
{
class Program
{
private void ReadIt(StreamReader sr, StreamWriter sw)
{
string line = sr.ReadLine();
int blank, lat;
String select = "";
while (line != null)
{
blank = line.Split(' ').Length;
if (line.Length == 80)
{
if (line.Substring(69, 3) == "RMS")
if (line.Substring(60, 20) == "EPOCH OF CURRENT MAP")
select = line.Substring(0, 24);
}
if (blank > 6)
{
try
{
if (line.Split(' ')[blank - 1] == "LAT/LON1/LON2/DLON/H")
{
lat = Convert.ToInt32(line.Split(' ')[4].Substring(0, 2));
if ((lat == 30))
{
line = sr.ReadLine();
line = sr.ReadLine();
sw.WriteLine(select + " " + line.Substring(56, line.Length - 57));
}
}
line = sr.ReadLine();
}
catch
{
line = sr.ReadLine();
}
}
}
}
static void Main(string[] args)
{
string[] dir = Directory.GetFiles(@"C:\Users\Suat\Desktop\ionex\2017");
int i = 0;
Program P = new Program();
StreamWriter sw = File.CreateText("C:/Users/Suat/Desktop/result.txt");
for (i = 0; i < dir.Length; i++)
{
Console.Clear();
Console.WriteLine(i.ToString() + "/" + dir.Length.ToString());
StreamReader sr = File.OpenText(dir[i]);
P.ReadIt(sr, sw);
sr.Close();
}
sw.Close();
}
}
}