-1

I am trying to run a vb.net script from SSIS to perform the following in a space delimited text;

  1. Loop through all files in directory (I've already coded this using .GetFiles)
  2. Within each text file loop through each line within the file
  3. Replace/Insert a value in the line
  4. Save the file

I'm struggling to come up with a method to replace/insert a value. I do not believe this is possible with ReadLines and my searches haven't turned up any solutions for my situation. All of the solutions I'm finding recommend using .split, but since this file is text delimited and column sizes vary, .split and .replace will not work.

Any ideas? Here is an example of a line from the text file and where I want to insert the value;

WMS0104        N00011              800171548-1    20190221                                                                                                                                  OVPRC                    <INSERT VALUE HERE>            PRINTER13           000000000000000000000000000000010000000000000000                                                                      00000000000000000000000000000000000000000000000000000000000000000000000000000     2019022108511300                                                                  00000000000000                                            00000000000000001
rando513
  • 11
  • 3

1 Answers1

0

Got it

        Dim BeforeWH_ID, ExistingWH_ID, AfterWH_ID, DesiredWH_ID, NewLineRecord As String

            DesiredWH_ID = "034                             "

            Dim lines() As String = IO.File.ReadAllLines(ExportFilePath)

            'Loop through each line in the array
            For i As Integer = 0 To lines.Length - 1

                'Fill line variables
                BeforeWH_ID = Mid(lines(i), 1, 215)
                ExistingWH_ID = Mid(lines(i), 215, 32)
                AfterWH_ID = Mid(lines(i), 247, 377)

                NewLineRecord = BeforeWH_ID & DesiredWH_ID & AfterWH_ID

                'Compare WH_ID
                If ExistingWH_ID <> DesiredWH_ID Then
                    'Replace the line in the array
                    lines(i) = NewLineRecord
                Else
                    'Keep the line in the array
                    lines(i) = lines(i)
                End If

                'Reset Variables
                BeforeWH_ID = Nothing
                ExistingWH_ID = Nothing
                AfterWH_ID = Nothing
                NewLineRecord = Nothing

            Next
            'Overrite existing file with line array
            IO.File.WriteAllLines(ExportFilePath, lines)
rando513
  • 11
  • 3