Click here to Skip to main content
14,668,908 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a process that creates a text file from a SQL data pull. It puts all the data into a text file and looks like (bob,1,12,50) I am trying to convert that text file to space and remove the commas to look like this

column1 column2 column 3 column4
data 1 data2 data3 data4

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

string s = File.ReadAllText(path);
File.WriteAllText(path, s.Replace(",", "\t"));
PIEBALDconsult 8-Jan-15 14:19pm
I would assume it's a large amount of data and recommend against having two full copies in memory -- I'd stream it one character at a time. I'd also protect against commas inside quotes.
Member 11362137 8-Jan-15 14:30pm
where in here would I put this

Private Sub SQL_Flatfile(ByVal LineEntry As String)


' .\ProgramData\DemoTeller\[EntryAssembly]\yyyyMMdd_Critical_Errors.log
Dim _FlatFileLogDirectory As String = "C:\Users\Liam\Documents\Visual Studio 2010\Projects\ConsoleApplication1"
If Directory.Exists(_FlatFileLogDirectory) = False Then Directory.CreateDirectory(_FlatFileLogDirectory)

Using _StreamWriter As New StreamWriter("FlatFile.txt", True)

End Using

Catch ex As Exception
End Try

End Sub
OriginalGriff 8-Jan-15 14:34pm
You need to specify VB in future: .NET is a framework, it works with many languages.
Using _StreamWriter As New StreamWriter("FlatFile.txt", True)
_StreamWriter.WriteLine(LineEntry.Replace(",", vbTab))
End Using

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100