Solved

VB.net Detect delimeter in any text file

Posted on 2016-07-22
2
45 Views
Last Modified: 2016-07-24
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
0
Comment
Question by:murbro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 41724998
instead of passing "," , you could pass sn char array of the couple of potential delimiters
with then the issue that none of those characters may appear in the data itself

otherwise you could write a detector function to check on a couple of lines how many times each of the potential delimiters appears...
0
 

Author Closing Comment

by:murbro
ID: 41726236
Thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Convert Ctime to date time in textfile? 7 62
VB.NET Textbox input validation 4 64
MYSQL responding very slow 3 49
Filtering a datagrid view 8 34
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question