Another question about regex (not understanding)

M

maggie

hi,

I've been working getting a file parsed out using Regex. There's something I
don't understand. When I define the pattern for my fields in my file, I am
telling regex to grab those fields ( strings and salary figures, numbers with
decimals) . Some of the fields contain commas, so that's why I'm using Regex.
This is a comma-delimited file. I am not understanding the Split command.
Right now , my file is being split into 4 occurrences, not the 25 or so , for
each field. I'm really stuck. Can somebody explain? I think that might help.
If my file is split on commas, then how do I tell Regex that? In the pattern?

thanks-
Code:
Dim objRE
Dim i As Integer
Dim pattern As String
pattern = " [a-z/.0-9]+([0-9,]{5}.[0-9]{2})" ' sort of works
objRE = New Regex(pattern)

'from 4guys  :

SplitAdv = Split(objRE.Replace(strInput, "\b"), "\b")
 
L

Lloyd Sheen

maggie said:
hi,

I've been working getting a file parsed out using Regex. There's something
I
don't understand. When I define the pattern for my fields in my file, I am
telling regex to grab those fields ( strings and salary figures, numbers
with
decimals) . Some of the fields contain commas, so that's why I'm using
Regex.
This is a comma-delimited file. I am not understanding the Split command.
Right now , my file is being split into 4 occurrences, not the 25 or so ,
for
each field. I'm really stuck. Can somebody explain? I think that might
help.
If my file is split on commas, then how do I tell Regex that? In the
pattern?

thanks-
Code:
Dim objRE
Dim i As Integer
Dim pattern As String
pattern = " [a-z/.0-9]+([0-9,]{5}.[0-9]{2})" ' sort of works
objRE = New Regex(pattern)

'from 4guys  :

SplitAdv = Split(objRE.Replace(strInput, "\b"), "\b")

Can you not use the CSV data provider to read the file. You can set up an
ODBC connection to the file and then read it in using the data classes
provided by dot.net.

I have used it in ASP.NET but should be the same. Create a BindingSource
and when you are asked to choose your data source select database , then MS
ODBC Data Source. You will have to create the ODBC source using the ODBC
Data Source Administrator. Basically you point to the file and use the
*.txt, *.csv driver. Once you have done that you can easily read the file
using the connection without all the worries you have right now.

Hope this helps
Lloyd Sheen
 
L

Lloyd Sheen

Lloyd Sheen said:
maggie said:
hi,

I've been working getting a file parsed out using Regex. There's
something I
don't understand. When I define the pattern for my fields in my file, I
am
telling regex to grab those fields ( strings and salary figures, numbers
with
decimals) . Some of the fields contain commas, so that's why I'm using
Regex.
This is a comma-delimited file. I am not understanding the Split command.
Right now , my file is being split into 4 occurrences, not the 25 or so ,
for
each field. I'm really stuck. Can somebody explain? I think that might
help.
If my file is split on commas, then how do I tell Regex that? In the
pattern?

thanks-
Code:
Dim objRE
Dim i As Integer
Dim pattern As String
pattern = " [a-z/.0-9]+([0-9,]{5}.[0-9]{2})" ' sort of works
objRE = New Regex(pattern)

'from 4guys  :

SplitAdv = Split(objRE.Replace(strInput, "\b"), "\b")

Can you not use the CSV data provider to read the file. You can set up an
ODBC connection to the file and then read it in using the data classes
provided by dot.net.

I have used it in ASP.NET but should be the same. Create a BindingSource
and when you are asked to choose your data source select database , then
MS ODBC Data Source. You will have to create the ODBC source using the
ODBC Data Source Administrator. Basically you point to the file and use
the *.txt, *.csv driver. Once you have done that you can easily read the
file using the connection without all the worries you have right now.

Hope this helps
Lloyd Sheen


I have a small example posted below. With it you don't even need to bother
with ODBC admin

Imports System.Data

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim conn As System.Data.Odbc.OdbcConnection
Dim dt As New DataTable
Dim da As System.Data.Odbc.OdbcDataAdapter
Dim connectionString As String
Dim importFolder As String
Dim fileName As String

importFolder = "C:\Users\Lloyd Sheen\Documents"
fileName = "Andy's Library.csv"

connectionString = "Driver={Microsoft Text Driver (*.txt;
*.csv)};Dbq=" + importFolder + ";"
conn = New Odbc.OdbcConnection(connectionString)


da = New System.Data.Odbc.OdbcDataAdapter("select * from [" +
fileName + "]", conn)
da.Fill(dt)

End Sub
End Class


You now have a datatable filled with your information.

Hope this helps
Lloyd Sheen
 
M

maggie

Hi Lloyd,

I had not thought of that. I'll try it. I eventually want to move this
program onto a file server and run it as an exe. Thanks again.

Lloyd Sheen said:
Lloyd Sheen said:
maggie said:
hi,

I've been working getting a file parsed out using Regex. There's
something I
don't understand. When I define the pattern for my fields in my file, I
am
telling regex to grab those fields ( strings and salary figures, numbers
with
decimals) . Some of the fields contain commas, so that's why I'm using
Regex.
This is a comma-delimited file. I am not understanding the Split command.
Right now , my file is being split into 4 occurrences, not the 25 or so ,
for
each field. I'm really stuck. Can somebody explain? I think that might
help.
If my file is split on commas, then how do I tell Regex that? In the
pattern?

thanks-
Code:
Dim objRE
Dim i As Integer
Dim pattern As String
pattern = " [a-z/.0-9]+([0-9,]{5}.[0-9]{2})" ' sort of works
objRE = New Regex(pattern)

'from 4guys  :

SplitAdv = Split(objRE.Replace(strInput, "\b"), "\b")

Can you not use the CSV data provider to read the file. You can set up an
ODBC connection to the file and then read it in using the data classes
provided by dot.net.

I have used it in ASP.NET but should be the same. Create a BindingSource
and when you are asked to choose your data source select database , then
MS ODBC Data Source. You will have to create the ODBC source using the
ODBC Data Source Administrator. Basically you point to the file and use
the *.txt, *.csv driver. Once you have done that you can easily read the
file using the connection without all the worries you have right now.

Hope this helps
Lloyd Sheen


I have a small example posted below. With it you don't even need to bother
with ODBC admin

Imports System.Data

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim conn As System.Data.Odbc.OdbcConnection
Dim dt As New DataTable
Dim da As System.Data.Odbc.OdbcDataAdapter
Dim connectionString As String
Dim importFolder As String
Dim fileName As String

importFolder = "C:\Users\Lloyd Sheen\Documents"
fileName = "Andy's Library.csv"

connectionString = "Driver={Microsoft Text Driver (*.txt;
*.csv)};Dbq=" + importFolder + ";"
conn = New Odbc.OdbcConnection(connectionString)


da = New System.Data.Odbc.OdbcDataAdapter("select * from [" +
fileName + "]", conn)
da.Fill(dt)

End Sub
End Class


You now have a datatable filled with your information.

Hope this helps
Lloyd Sheen
 
M

maggie

Why didn't I do this before? for some weird reason, I had to use regex. Dumb,
dumb,dumb. I can't tell you how much time I spent on it. I was close though.
Thanks so much Lloyd. You saved me! :):):)
 
L

Lloyd Sheen

maggie said:
Why didn't I do this before? for some weird reason, I had to use regex.
Dumb,
dumb,dumb. I can't tell you how much time I spent on it. I was close
though.
Thanks so much Lloyd. You saved me! :):):)

maggie said:
hi,

I've been working getting a file parsed out using Regex. There's
something I
don't understand. When I define the pattern for my fields in my file, I
am
telling regex to grab those fields ( strings and salary figures, numbers
with
decimals) . Some of the fields contain commas, so that's why I'm using
Regex.
This is a comma-delimited file. I am not understanding the Split command.
Right now , my file is being split into 4 occurrences, not the 25 or so ,
for
each field. I'm really stuck. Can somebody explain? I think that might
help.
If my file is split on commas, then how do I tell Regex that? In the
pattern?

thanks-
Code:
Dim objRE
Dim i As Integer
Dim pattern As String
pattern = " [a-z/.0-9]+([0-9,]{5}.[0-9]{2})" ' sort of works
objRE = New Regex(pattern)

'from 4guys  :

SplitAdv = Split(objRE.Replace(strInput, "\b"), "\b")

Glad that helps. What I have found with all the classes provided in dot.net
there is very little need to re-invent the wheel.

LS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top