replace code

net1720

New member
Joined
Sep 17, 2007
Messages
1
Programming Experience
3-5
Hello,

I tried this code to replace a tab delimited file to a comma delimited file with notepad files. What I did was replace tabs with commas. This worked fine until I used the notepad files from the spooler and it will not do anything. I think the issue here is that the notepad files from the spooler are not tab delimited, but rather just whitespaces. Any suggestions?? Any help and feedback would be appreciated!
Here is the code I used:

VB.NET:
Dim MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("C:\test.txt")

        MyReader.TextFieldType = FileIO.FieldType.Delimited
        MyReader.SetDelimiters(",")

        Dim sContents As String = IO.File.ReadAllText("C:\test.txt")
        sContents = sContents.Replace(ControlChars.Tab, ","c)


net1720
 
Last edited by a moderator:
Those files are not delimited at all. They are fixed-width. Each field occupies a fixed-width "column" in the text, with unused characters in each field occupied by spaces. You need to know how wide each "column" is so you can determine how many spaces are padding each value, then you can replace each substring of padding spaces with commas.
 
Back
Top