Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

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("Description", GetType([String]))
Using sr As New StreamReader("D:\Temp\fileread\readtext.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
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

Thanks