≡ Menu




how to write a tab delimited text file using C#.net

Use following Code

StreamReader sr = new StreamReader(@"d:simpleTabDelimeterFile.txt");
                StreamWriter outputFile = new StreamWriter(@"d:out.txt");
                string strline = "";            

                string[] _values = null;
                while (!sr.EndOfStream)
                {
                    strline = sr.ReadLine();
                    _values = strline.Split('t');
                    if( _values.Length == 3 )  
                    {
                        strline = _values[0] + 't' + _values[1] + 't' + _values[2];
                        outputFile.WriteLine(strline);
                    }
                }
                sr.Close();
                outputFile.Close();

Comments on this entry are closed.