|
-
Apr 17th, 2007, 09:26 AM
#1
Thread Starter
Addicted Member
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
-
Apr 17th, 2007, 09:56 AM
#2
Fanatic Member
Re: comma delimited
vb Code:
Dim NewString As String
'replace the commas in the string with the data with spaces
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!
-
Apr 17th, 2007, 10:05 AM
#3
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.
-
Apr 17th, 2007, 10:07 AM
#4
Fanatic Member
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!
-
Apr 17th, 2007, 10:38 AM
#5
Re: comma delimited
Try this function... It'll read the csv file and return a datatable
vb Code:
Private Function CsvToDataTable(ByVal filePath As String) As DataTable
Dim dt As DataTable = Nothing
Dim sourcePath As String = String.Empty
Dim csvFile As String = String.Empty
Dim conString As String = String.Empty
Dim conn As OleDb.OleDbConnection = Nothing
Dim adapter As OleDb.OleDbDataAdapter = Nothing
Dim selString As String = String.Empty
Try
sourcePath = System.IO.Path.GetDirectoryName(filePath)
csvFile = System.IO.Path.GetFileName(filePath)
conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sourcePath & ";Extended Properties=""text;HDR=No;FMT=Delimited"";"
conn = New OleDb.OleDbConnection(conString)
selString = "Select * From " & csvFile
adapter = New OleDb.OleDbDataAdapter(selString, conn)
dt = New DataTable(System.IO.Path.GetFileNameWithoutExtension(filePath))
conn.Open()
adapter.Fill(dt)
conn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
adapter.Dispose()
conn.Dispose()
End Try
Return dt
End Function
-
Apr 17th, 2007, 10:51 AM
#6
Thread Starter
Addicted Member
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
-
Apr 17th, 2007, 11:00 AM
#7
Thread Starter
Addicted Member
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
-
Apr 17th, 2007, 11:16 AM
#8
Thread Starter
Addicted Member
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
-
Apr 17th, 2007, 03:07 PM
#9
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|