Solved

VB.net Detect delimeter in any text file

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

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now