What's the best way to validate a CSV file

A

Ali-R

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
 
S

Sahil Malik

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/
 
C

Cor Ligthert

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
 
A

Ali-R

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
 
A

Ali-R

You actual presented two solutions:

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
 
A

Ali-R

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
 

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

Top