csv - C#: Checking That ArrayList Elements have specific type -
csv - C#: Checking That ArrayList Elements have specific type -
arraylist filelist = new arraylist(); private void button2_click(object sender, eventargs e) { if (openfiledialog1.showdialog() == dialogresult.ok) { string line; // read file , display line line. system.io.streamreader file = new system.io.streamreader(openfiledialog1.filename); while ((line = file.readline()) != null) { // puts elements in table filelist.add(line.split(';')); } file.close(); } (int = 0; < filelist.count; i++) { (int x = 0; x < (filelist[i] string[]).length; x++) { // if (x ==0) // { //filelist[0] must int // } // if (x==1) //filelist[1] must string this.textbox2.text += ((filelist[i] string[])[x] + " "); } this.textbox2.text += environment.newline; } }
i far here.
i take elements csv file.
i need sure 1 column has numbers-integers (1,2,3,4,5), sec column has names(so have type string or character), 3rd surnames etc. etc.
the rows presented : 1;george;mano;
how can sure csv file has right types?
i think more code problem placed within 2 statements.
thank much,
george.
edit: know it's csv, here's columnar reply ;-)
your arraylist
contains string[]
, need verify each array has appropriate type of string.
for (int = 0; < filelist.count; i++) { string[] lineitems = (string[])filelist[i]; if (!regex.ismatch (lineitems[0], "^\d+$")) // numbers throw new argumentexception ("invalid id @ row " + i); if (!regex.ismatch (lineitems[1], "^[a-za-z]+$")) // surnames - letters-only throw new argumentexception ("invalid surname @ row " + i); if (!regex.ismatch (lineitems[2], "^[a-za-z]+$")) // names - letters-only throw new argumentexception ("invalid name @ row " + i); }
c# csv arraylist validation
Comments
Post a Comment