我正在尝试从SSIS运行vb.net脚本,以空格分隔的文本执行以下操作;
我正在努力提出一种替换/插入值的方法。我认为ReadLines不可能做到这一点,我的搜索还没有找到适合我情况的解决方案。我找到的所有解决方案都建议使用.split,但是由于此文件是用文本定界的并且列大小各不相同,因此.split和.replace将无法工作。
有什么想法吗?这是文本文件中一行的示例,我想在其中插入值;
WMS0104 N00011 800171548-1 20190221 OVPRC <INSERT VALUE HERE> PRINTER13 000000000000000000000000000000010000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000 2019022108511300 00000000000000 00000000000000001
答案 0 :(得分:0)
知道了
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)