What's the best way to validate a CSV file

  • Thread starter Thread starter Ali-R
  • Start date Start date
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
 
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,

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
 
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
 
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
 
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
 
Back
Top