Link to home
Start Free TrialLog in
Avatar of GREEBA
GREEBA

asked on

Read a VBNet file using a tilde as deliminator instead of a comma

I would like to read a simple tilde deliminated file consisting of ten fields per record. In old fashioned basic we used to be able to specify the deliminator... How do I specify the deliminator  in VBNet?

Thanks
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

.NET version?

Bob
Avatar of GREEBA
GREEBA

ASKER

Bob

.net Professional Version 2002

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America 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
Thanks, Mikey.  I was hoping for the opportunity to show delimited text parsing with 2005.  Too bad, huh?

Bob
Lol...you itching for something to do  today Bob?

Post it anways.  =)

SOLUTION
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
Minor change for different delimiter:

     reader.Delimiters = New String() {"~"}

Bob
Sweet...so many things to discover in .Net.

I myself had not encountered the TextFieldParser() class yet.  =)

Thanx for sharing...
Or even one form, one button, one datagrid and this code

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim dt As DataTable = ReadFile("C:\Test", "tildesep.txt")
        DataGrid1.DataSource = dt
    End Sub

    Private Function ReadFile(ByVal sourcepath As String, ByVal sourcefile As String) As DataTable
        Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sourcepath & ";Extended Properties=""text"";"
        Dim SQL As String = "SELECT * FROM " & sourcefile
        Dim Con As New OleDbConnection(ConStr)
        Dim da As New OleDbDataAdapter(SQL, Con)
        Dim dt As New DataTable
        Try
            da.Fill(dt)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return dt
    End Function

With a Schema.ini file, in the same directory as the sourcefile, containing

[tildesep.txt]
Format=Delimited(~)

Done in VB.NET 2003, but translates to 2005 OK.

Roger
Hellooooo, Roger dodger ;)

Bob
Hi all.

I see I missed the boat.  Must have been closed whilst I was testing.  ;-)

Roger