I'm trying to write a program which changes the column order of a CSV file.
Im using the following code
Public Shared Sub ReadCSV()
Dim columnstoselect As String()
Dim csvFile As String = "D:\Projects\MQA_Remap_CSV\Input.csv"
Dim lines = File.ReadAllLines(csvFile)
Dim outFile As String = "D:\Projects\MQA_Remap_CSV\Output.csv"
Dim data As String()
Dim format As String = CReadConfig.ReadConfigSource("D:\Projects\MQA_Remap_CSV\config.csv")
Form1.TextBox1.Text = CReadConfig.ReadConfigtarget("D:\Projects\MQA_Remap_CSV\config.csv").ToString
Using fs As New StreamWriter(outFile, False)
For Each s As String In lines
data = s.Split(","c)
fs.WriteLine(String.Format(format, CReadConfig.ReadConfigtarget("D:\Projects\MQA_Remap_CSV\config.csv").ToArray
)
)
Next
End Using
I am having a problem with this function
CReadConfig.ReadConfigtarget("D:\Projects\MQA_Remap_CSV\config.csv")
the function looks like this
Public Shared Function ReadConfigtarget(filePath As String) As List(Of String)
Dim str As String()
Dim lines = File.ReadAllLines(filePath).Skip(1)
Dim val As String
Dim i As String = 0
Using sr As New StreamReader(filePath)
Dim out As New List(Of String)
For Each s As String In lines
str = s.Split(","c)
val = Trim("data(" & (str(1) - 1) & ") ").ToString
out.Add(val)
Next
Return out
End Using
End Function
this function reads a csv file and should return a list of values which look like this
data(0), data(1)
so in effect if i replace this line
fs.WriteLine(String.Format(format, CReadConfig.ReadConfigtarget("D:\Projects\MQA_Remap_CSV\config.csv").ToArray
with
fs.WriteLine(String.Format(format, data(0), data(1), data(2))
the code works and writes out the data in data(0) ,data(1) and so on , however when i use the function it is taking it as a literal string and writing out text 'data(0)' , data(1) in the csv file.
Any ideas on how to pass the function values as argument and not literal text?