Script Component for vbCrLf -> vbLf EXCEPT for row delimiter

  • I have the following script. It converts any CRLFs in the flat file to LFs. I only want this to happen when the CRLFs are are not the row delimiter. This flat file has a | delimiter for columns, and " for text. ALL fields are text.

    Dim file As New System.IO.StreamReader("\\MyServer\D$\MyFolder\MyFile.txt")

    Dim data As String

    data = file.ReadToEnd()

    data = data.Replace(vbCrLf, vbLf) -- I ONLY WANT TO DO THIS IF IT'S NOT THE ROW DELIMITER

    file.Close()

    Dim writer As New System.IO.StreamWriter(("\\MyServer\D$\MyFolder\MyFile.txt"), False)

    writer.Write(data)

    writer.Flush()

    writer.Close()

    Can someone please help me with the syntax to ignore the replace when it's the row delimiter?f

    [font="Courier New"]ZenDada[/font]

  • One option is to use a data flow, and relapce crlf with lf in each field, and save it back out. Might be problematic in ssis though...

    The other option is to build a regex that matches a full line, and do the replace on the characters that match, then write the line out followed by a crlf. Repeat for the next match.

    Untested regex to match a 3 field line( on my phone, can't test this):

    "[^"]*"|"[^"]*"|"[^"]*"

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply