I am reading a csv file which has following data format
14-Sep-12 ALUMINI 31-Dec-12 117.65 119.25 117.65 118.9 116.75 36
14-Sep-12 ALUMINI 30-Nov-12 116.95 118.65 116.8 118.4 116.5 252
14-Sep-12 ALUMINI 31-Oct-12 116.45 118.15 116.05 117.85 116.05 2802
I am reading this data with following code
List<string> sc = new List<string>();
filepath = "abc.csv" ;
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);
StreamReader sr = new StreamReader(fs);
if (fs != null)
{
while ((oneLine = sr.ReadLine()) != null)
{
sc.Add(oneLine);
}
sr.Close();
// Now writing above data in some file , fo and fout are already declared
fo = new FileStream("tempd.txt", FileMode.Append, FileAccess.Write);
fout = new StreamWriter(fo);
foreach (string str in sc)
{
// i am using ' ' as one of my splitter character
char[] splitter = { ' ', ',', '\t' };
string[] sa1 = str.Split(splitter);
string wline = sa1[0] + "," + sa1[1] + "," + sa1[5] + "," + sa1[6] + "," + sa1[7] ;
fout.WriteLine(wline);
}
fout.Close();
}
My biggest problem is first column of of data is 14-Sep-2012 has been changed to 14 Sep 2012 (- is missing). Which is creating problem in my rest of application.
Is there any way by which I can convert date format while reading and writing file, I want to store this date 14-Sep-2012 as 2012-9-14.
I think this is the answer you are looking for.