473,395 Members | 1,931 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

What's the best way to validate a CSV file

Hi all,
I am getting a CSV file like this from our client:

"C1","2","12344","Mr","John","Chan","05/07/1976".........

I need to validate **each filed value** against a set of rules ,for instance
for "05/07/1976" ,I need to make sure that it's in the right format ,It's
not later than today and lots of other rules ,Is there somebody who can help
me how to that?Can I map it to some sort of xml schema or something?

Thanks for your help.

Ali-R
Nov 16 '05 #1
7 16202
Couple of ways.

String.Split to seperate parts of it, and regex validate it.

Or

string.replace commas for some xml tag, prepend it one additional tag, and
then validate against a schema.

There might be better ways of doing it though.

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/

"Ali-R" <Al**@microsft.com> wrote in message
news:uj**************@TK2MSFTNGP15.phx.gbl...
Hi all,
I am getting a CSV file like this from our client:

"C1","2","12344","Mr","John","Chan","05/07/1976".........

I need to validate **each filed value** against a set of rules ,for instance for "05/07/1976" ,I need to make sure that it's in the right format ,It's
not later than today and lots of other rules ,Is there somebody who can help me how to that?Can I map it to some sort of xml schema or something?

Thanks for your help.

Ali-R

Nov 16 '05 #2
Ali,

In the same way as it was done forever, even when it was on paper or stone.

Just read them one by one, and test every object in it against the rules
that are for that.

Why would that have changed?

Cor
Nov 16 '05 #3
Hi Sahil,

We came across eachother again( do you remember the hot issue on Datareader
and Dataset in ado.net group-Disconnected vs connected approach)

Anyways,You say that
String.Split to seperate parts of it, and regex validate it. Imagine that I have split the CSV file into an ArrayList ,,How can I use
regex to validate it
? what's regex?

Thanks

"Sahil Malik" <co*****************@nospam.com> wrote in message
news:uk**************@TK2MSFTNGP15.phx.gbl... Couple of ways.

String.Split to seperate parts of it, and regex validate it.

Or

string.replace commas for some xml tag, prepend it one additional tag, and
then validate against a schema.

There might be better ways of doing it though.

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/

"Ali-R" <Al**@microsft.com> wrote in message
news:uj**************@TK2MSFTNGP15.phx.gbl...
Hi all,
I am getting a CSV file like this from our client:

"C1","2","12344","Mr","John","Chan","05/07/1976".........

I need to validate **each filed value** against a set of rules ,for

instance
for "05/07/1976" ,I need to make sure that it's in the right format
,It's
not later than today and lots of other rules ,Is there somebody who can

help
me how to that?Can I map it to some sort of xml schema or something?

Thanks for your help.

Ali-R


Nov 16 '05 #4
Yes I remember you Ali :) Nice to run into you again.

You might want to check this out -
http://msdn.microsoft.com/XML/XMLCod...lcsvreader.asp

Regex is under System.Text.RegularExpressions - it is used for text matching
based on a pattern. It's pretty awesome once you get used to it.
--

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/

"Ali-R" <Al**@microsft.com> wrote in message
news:#0**************@TK2MSFTNGP14.phx.gbl...
Hi Sahil,

We came across eachother again( do you remember the hot issue on Datareader and Dataset in ado.net group-Disconnected vs connected approach)

Anyways,You say that
String.Split to seperate parts of it, and regex validate it.

Imagine that I have split the CSV file into an ArrayList ,,How can I use
regex to validate it
? what's regex?

Thanks

"Sahil Malik" <co*****************@nospam.com> wrote in message
news:uk**************@TK2MSFTNGP15.phx.gbl...
Couple of ways.

String.Split to seperate parts of it, and regex validate it.

Or

string.replace commas for some xml tag, prepend it one additional tag, and then validate against a schema.

There might be better ways of doing it though.

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/

"Ali-R" <Al**@microsft.com> wrote in message
news:uj**************@TK2MSFTNGP15.phx.gbl...
Hi all,
I am getting a CSV file like this from our client:

"C1","2","12344","Mr","John","Chan","05/07/1976".........

I need to validate **each filed value** against a set of rules ,for

instance
for "05/07/1976" ,I need to make sure that it's in the right format
,It's
not later than today and lots of other rules ,Is there somebody who can

help
me how to that?Can I map it to some sort of xml schema or something?

Thanks for your help.

Ali-R



Nov 16 '05 #5
You actual presented two solutions:
> String.Split to seperate parts of it, and regex validate it.
> Or
> string.replace commas for some xml tag, prepend it one additional
> tag,and then validate against a schema.

System.Text.RegularExpressions is used for the first one and the link you
sent me is for the second one,right? (just checking)

I will send you my other questions as soon as I make sure I was right...

Thanks sohil,like always your solutions are unique;-)

Ali-R

"Sahil Malik" <co*****************@nospam.com> wrote in message
news:Oe**************@TK2MSFTNGP12.phx.gbl...
Yes I remember you Ali :) Nice to run into you again.

You might want to check this out -
http://msdn.microsoft.com/XML/XMLCod...lcsvreader.asp

Regex is under System.Text.RegularExpressions - it is used for text
matching
based on a pattern. It's pretty awesome once you get used to it.
--

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/

"Ali-R" <Al**@microsft.com> wrote in message
news:#0**************@TK2MSFTNGP14.phx.gbl...
Hi Sahil,

We came across eachother again( do you remember the hot issue on

Datareader
and Dataset in ado.net group-Disconnected vs connected approach)

Anyways,You say that
> String.Split to seperate parts of it, and regex validate it.

Imagine that I have split the CSV file into an ArrayList ,,How can I use
regex to validate it
? what's regex?

Thanks

"Sahil Malik" <co*****************@nospam.com> wrote in message
news:uk**************@TK2MSFTNGP15.phx.gbl...
> Couple of ways.
>
> String.Split to seperate parts of it, and regex validate it.
>
> Or
>
> string.replace commas for some xml tag, prepend it one additional tag,

and > then validate against a schema.
>
> There might be better ways of doing it though.
>
> - Sahil Malik
> http://codebetter.com/blogs/sahil.malik/
>
>
>
> "Ali-R" <Al**@microsft.com> wrote in message
> news:uj**************@TK2MSFTNGP15.phx.gbl...
>> Hi all,
>> I am getting a CSV file like this from our client:
>>
>> "C1","2","12344","Mr","John","Chan","05/07/1976".........
>>
>> I need to validate **each filed value** against a set of rules ,for
> instance
>> for "05/07/1976" ,I need to make sure that it's in the right format
>> ,It's
>> not later than today and lots of other rules ,Is there somebody who
>> can
> help
>> me how to that?Can I map it to some sort of xml schema or something?
>>
>> Thanks for your help.
>>
>> Ali-R
>>
>>
>
>



Nov 16 '05 #6
Sahil,

The problem with String.split is that in my CSV file I'm using this format:

"fieldvalue1","fieldValue2",..... (I mean there is a double qoute around
each filed value) can it parse sucha CSV file?

I think I have to use a custom impelmentation to seperate CSV field Values
into an array list and then use regx t validate it ,right?

thanks
"Sahil Malik" <co*****************@nospam.com> wrote in message
news:Oe**************@TK2MSFTNGP12.phx.gbl...
Yes I remember you Ali :) Nice to run into you again.

You might want to check this out -
http://msdn.microsoft.com/XML/XMLCod...lcsvreader.asp

Regex is under System.Text.RegularExpressions - it is used for text
matching
based on a pattern. It's pretty awesome once you get used to it.
--

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/

"Ali-R" <Al**@microsft.com> wrote in message
news:#0**************@TK2MSFTNGP14.phx.gbl...
Hi Sahil,

We came across eachother again( do you remember the hot issue on

Datareader
and Dataset in ado.net group-Disconnected vs connected approach)

Anyways,You say that
> String.Split to seperate parts of it, and regex validate it.

Imagine that I have split the CSV file into an ArrayList ,,How can I use
regex to validate it
? what's regex?

Thanks

"Sahil Malik" <co*****************@nospam.com> wrote in message
news:uk**************@TK2MSFTNGP15.phx.gbl...
> Couple of ways.
>
> String.Split to seperate parts of it, and regex validate it.
>
> Or
>
> string.replace commas for some xml tag, prepend it one additional tag, and > then validate against a schema.
>
> There might be better ways of doing it though.
>
> - Sahil Malik
> http://codebetter.com/blogs/sahil.malik/
>
>
>
> "Ali-R" <Al**@microsft.com> wrote in message
> news:uj**************@TK2MSFTNGP15.phx.gbl...
>> Hi all,
>> I am getting a CSV file like this from our client:
>>
>> "C1","2","12344","Mr","John","Chan","05/07/1976".........
>>
>> I need to validate **each filed value** against a set of rules ,for
> instance
>> for "05/07/1976" ,I need to make sure that it's in the right format
>> ,It's
>> not later than today and lots of other rules ,Is there somebody who
>> can
> help
>> me how to that?Can I map it to some sort of xml schema or something?
>>
>> Thanks for your help.
>>
>> Ali-R
>>
>>
>
>



Nov 16 '05 #7
How do you define the rules?

Thanks
"Cor Ligthert" <no************@planet.nl> wrote in message
news:ON****************@TK2MSFTNGP14.phx.gbl...
Ali,

In the same way as it was done forever, even when it was on paper or
stone.

Just read them one by one, and test every object in it against the rules
that are for that.

Why would that have changed?

Cor

Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Brian van den Broek | last post by:
Hi all, I'm just starting to employ unit testing (I'm using doctest), and I am uncertain how to handle writing tests where the behaviour being tested is dependant on whether certain file paths...
39
by: Holly | last post by:
I'm trying to validate my code and I can't figure out what kind of doctype I have. The validator can't tell me anything because it can't move beyond the doctype declaration. ...
8
by: Dean Speir | last post by:
Hi... I've been referred to this Newsgroup by the W3C Markup Validator FAQ. I've been happily using this Validator <http://validator.w3.org> for the past 18 months with great success, but...
9
by: AFN | last post by:
I was just dropped into someone else's code (isn't that always so fun?). I can't figure out why a custom validation control's server event function is executing. There is nothing (that I see)...
10
by: Mike Logan | last post by:
I am using the "contract first" design methodology. Contract First is design the WSDL first then design the server and client. However I must design my XSD/XML Schema before anything. I am...
1
by: KMZ_state | last post by:
We have a debate here. We are receiving a CSV file specified by the user and need to validate the contents, writing the "good" records to the database and displaying the "bad" records to the user....
1
by: thomas.porschberg | last post by:
Hi XML-gurus, imagine a provider of some information in XML format and a client who reads this data. Both sides share a XSD as a contract. I think this is quite common. Now the client wants...
5
by: Ryan Liu | last post by:
I have an application need export ane import data of projects. There are about 10 database tables releated to one project. 3 of them each could have up to 100K lines data. I can export all data...
6
by: Jonny | last post by:
Hi, I'm trying to validate my xml against a xsd but I can't get it to work. Originally, I wanted to validate an xml string but since I didn't get that to work I tried to validate an xml file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.