Results 1 to 9 of 9

Thread: comma delimited

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    comma delimited

    Hi gurus

    As you can tell by my previous post, I am new to VB so please go easy on me.

    I have a csv file but with in the file there is a field that comes like this

    " joh,smith" ,

    so the first line looks like this

    03/03/03,"xxxx","xxxxx","name name",xxxx,03/03/03,1.19,"xxxxx","name,name"


    I would like to make this comma that is within the quotes a space or a blank so I can use split cleantly and get what I need to do .

    How can I do this, all help is really welcome.

    Thanks a bunch gurus

  2. #2
    Fanatic Member
    Join Date
    Aug 2006
    Location
    Chicago, IL
    Posts
    514

    Re: comma delimited

    vb Code:
    1. Dim NewString As String
    2.  
    3. 'replace the commas in the string with the data with spaces
    4. NewString = commaData.Replace(",", Chr(8).Tostring)
    Warren Ayen
    Senior C# Developer
    DLS Software Studios (http://www.dlssoftwarestudios.com/)

    I use Microsoft Visual Studio 2005, 2008, working with Visual Basic and Visual C#
    Hey! If you like my post, or I solve your issue, please Rate Me!

  3. #3
    Fanatic Member bgmacaw's Avatar
    Join Date
    Mar 2007
    Location
    Atlanta, GA USA
    Posts
    524

    Re: comma delimited

    Check out this thread that offers several solutions: http://www.vbforums.com/showthread.php?t=445800

    Mine is the last in that thread and demonstrates using the VS2005 TextFieldParser engine to handle this.

  4. #4
    Fanatic Member
    Join Date
    Aug 2006
    Location
    Chicago, IL
    Posts
    514

    Re: comma delimited

    Oops. I removed my solution - I misread what he'd been asking for. Sorry
    Warren Ayen
    Senior C# Developer
    DLS Software Studios (http://www.dlssoftwarestudios.com/)

    I use Microsoft Visual Studio 2005, 2008, working with Visual Basic and Visual C#
    Hey! If you like my post, or I solve your issue, please Rate Me!

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: comma delimited

    Try this function... It'll read the csv file and return a datatable
    vb Code:
    1. Private Function CsvToDataTable(ByVal filePath As String) As DataTable
    2.         Dim dt As DataTable = Nothing
    3.         Dim sourcePath As String = String.Empty
    4.         Dim csvFile As String = String.Empty
    5.         Dim conString As String = String.Empty
    6.         Dim conn As OleDb.OleDbConnection = Nothing
    7.         Dim adapter As OleDb.OleDbDataAdapter = Nothing
    8.         Dim selString As String = String.Empty
    9.         Try
    10.             sourcePath = System.IO.Path.GetDirectoryName(filePath)
    11.             csvFile = System.IO.Path.GetFileName(filePath)
    12.             conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sourcePath & ";Extended Properties=""text;HDR=No;FMT=Delimited"";"
    13.             conn = New OleDb.OleDbConnection(conString)
    14.             selString = "Select * From " & csvFile
    15.             adapter = New OleDb.OleDbDataAdapter(selString, conn)
    16.             dt = New DataTable(System.IO.Path.GetFileNameWithoutExtension(filePath))
    17.             conn.Open()
    18.             adapter.Fill(dt)
    19.             conn.Close()
    20.         Catch ex As Exception
    21.             MessageBox.Show(ex.Message)
    22.         Finally
    23.             adapter.Dispose()
    24.             conn.Dispose()
    25.         End Try
    26.         Return dt
    27.     End Function

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: comma delimited

    Thanks gurus

    I only want to change the las field from "name,name" to "name name" as you can tell from the i.e all other fields are ok just the last one.

    I am using vs2003

    Thanks again

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: comma delimited

    Thanks gurus

    I only want to change the las field from "name,name" to "name name" as you can tell from the i.e all other fields are ok just the last one.

    I am using vs2003

    Thanks again

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: comma delimited

    thanks Big S

    I heard you on the ado but how would I go using IO regular net, I want to read a hold line
    03/03/03,"xxxx","xxxxx","name name",xxxx,03/03/03,1.19,"xxxxx","name,name"

    and change only the "name,name" to "name name" leaqving everything just like this

    03/03/03,"xxxx","xxxxx","name name",xxxx,03/03/03,1.19,"xxxxx","name name"

    Thanks a bunch

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: comma delimited

    stanav? anyone please

    Thanks a bunch guys for battling with me here

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width