Solved

VB.net Detect delimeter in any text file

Posted on 2016-07-22
2
50 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

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 …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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 …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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