Murray Brown
asked on
VB.net Detect delimeter in any text file
Hi
I am trying to find a way to write VB.net code that can convert any text file into a DataTable
I found the following example that uses a comma delimeter. Is there a way to detect the delimiter?
Dim dt As New DataTable()
dt.Columns.Add("Row No", GetType(Int32))
dt.Columns.Add("Col No", GetType(Int32))
dt.Columns.Add("Width", GetType(Int32))
dt.Columns.Add("Height", GetType(Int32))
dt.Columns.Add("ImageUrl", GetType([String]))
dt.Columns.Add("Descriptio n", GetType([String]))
Using sr As New StreamReader("D:\Temp\file read\readt ext.txt")
While (InlineAssignHelper(line, sr.ReadLine())) IsNot Nothing
Dim parts As String() = line.Split(","C)
Dim dr = dt.NewRow()
'use newrow to create new row
For i As Integer = 0 To parts.Length - 1
dr(i) = parts(i)
Next
'add row to datatable now
dt.Rows.Add(dr)
End While
sr.Close()
End Using
I am trying to find a way to write VB.net code that can convert any text file into a DataTable
I found the following example that uses a comma delimeter. Is there a way to detect the delimiter?
Dim dt As New DataTable()
dt.Columns.Add("Row No", GetType(Int32))
dt.Columns.Add("Col No", GetType(Int32))
dt.Columns.Add("Width", GetType(Int32))
dt.Columns.Add("Height", GetType(Int32))
dt.Columns.Add("ImageUrl",
dt.Columns.Add("Descriptio
Using sr As New StreamReader("D:\Temp\file
While (InlineAssignHelper(line, sr.ReadLine())) IsNot Nothing
Dim parts As String() = line.Split(","C)
Dim dr = dt.NewRow()
'use newrow to create new row
For i As Integer = 0 To parts.Length - 1
dr(i) = parts(i)
Next
'add row to datatable now
dt.Rows.Add(dr)
End While
sr.Close()
End Using
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER