Hello all,
Thanks in advance for any type of help, i want to create a text file from already created textfile, which will have all the "\t" characters replaced with "\n" e.g
abc.txt
ammar hassan
shah naqvi
new.txt
ammar
hassan
shah
naqvi
here is the code i m using, but it's not showing my required output
String line = "";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;
ArrayList arr = new ArrayList();
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader(openFileDialog1.FileName))
{
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
foreach (string s in line.Split(new char []{'\t'}))
{
string ss = s;
ss += "\n";
arr.Add(ss);
} //Console.WriteLine(line);
}
}
}
catch (Exception ex)
{
// Let the user know what went wrong.
MessageBox.Show(ex.Message);
}
// MessageBox.Show(line);
string str = "";
for (int i = 0; i < arr.Count; i++)
{
//using (sw)
//{
str += arr[i].ToString();
//}
}
MessageBox.Show(str);
using (StreamWriter sw = new StreamWriter("TestFile.txt"))
{ sw.WriteLine("ghv");
sw.Write("g");
sw.WriteLine("ghv");
}
}