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
Solved

VB.net Detect delimeter in any text file

Posted on 2016-07-22
2
41 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
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 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