code for convert the space delimited to comma delimited in text file

Posted by sailulakshmid-21627 under C# on 6/19/2013 | Points: 10 | Views : 1826 | Status : [Member] | Replies : 1
code for convert the space delimited to comma delimited in text file using c#.net with example




Responses

Posted by: Kmandapalli on: 6/19/2013 [Member] Silver | Points: 25

Up
0
Down
Hi,

Get the data from the text file into StearmWriter, then replace the space with comma sumthing like this:

private static void TextFile(string filename)
{
FileStream fsOut = File.Create(filename+"_out");
FileStream fsIn = File.OpenRead(filename);
StreamReader sr = new StreamReader(fsIn);
StreamWriter sw = new StreamWriter(fsOut);
while (!sr.EndOfStream)
{
string inputLine = sr.ReadLine();
string terminator = (sr.EndOfStream ? "" : ",");
sw.Write(inputLine + terminator);
}
sw.Flush();
fsOut.Close();
}

Mark as Answer if satisfied.

Regards,
Shree M.


Kavya Shree Mandapalli

sailulakshmid-21627, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response