Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6131569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:59:28+00:00 2026-05-23T16:59:28+00:00

ArrayList fileList = new ArrayList(); private void button2_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog()

  • 0
               ArrayList fileList = new ArrayList();


      private void button2_Click(object sender, EventArgs e)
            {
          if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
            string line;

            // Read the file and display it line by 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();
        }

        for (int i = 0; i < fileList.Count; i++)
        {
            for (int x = 0; x < (fileList[i] as string[]).Length; x++)
            {
               // if (x ==0)
              //  { 
                    //fileList[0] must Be int 
              //  }
               // if (x==1)
                    //fileList[1] must be string 

                this.textBox2.Text += ((fileList[i] as string[])[x] + " ");
            }

            this.textBox2.Text += Environment.NewLine;
        }
    }

I am so far here.

I take the elements from a CSV file.

I need now to be sure that the 1 column has only numbers-integers (1,2,3,4,5), the second column has only names(so it will have the type string or character), the third surnames etc. etc.

The rows are presented like this : 1;George;Mano;

How can I be sure that the CSV file has the correct types?

I think that any more code about this problem will be placed inside the 2 for statements.

Thank you very much,

George.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:59:29+00:00Added an answer on May 23, 2026 at 4:59 pm

    Edit: Now that we know it’s really CSV, here’s a columnar answer 😉

    Your ArrayList contains string[], so you need to verify that each array has the appropriate type of string.

    for (int i = 0; i < fileList.Count; i++)
    {
       string[] lineItems = (string[])fileList[i];
       if (!Regex.IsMatch (lineItems[0], "^\d+$")) // numbers
          throw new ArgumentException ("invalid id at row " + i);
       if (!Regex.IsMatch (lineItems[1], "^[a-zA-Z]+$")) // surnames - letters-only
          throw new ArgumentException ("invalid surname at row " + i);
       if (!Regex.IsMatch (lineItems[2], "^[a-zA-Z]+$")) // names - letters-only
          throw new ArgumentException ("invalid name at row " + i);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

private ArrayList<String> colors = new ArrayList<String>(); Looking at the example above, it seems the
ArrayList<Object> list = new ArrayList<Object>(); list.add(1); list.add(Java); list.add(3.14); System.out.println(list.toString()); I tried: ArrayList<String> list2 =
ArrayList<HashMap<String, String>> arrayListRowsFirst = new ArrayList<HashMap<String, String>>(); Today when i was going through a
ArrayList<String> veri1 = new ArrayList<String>(); String[] veri2 = {Fatih, Ferhat, Furkan}; How can I
I have a ArrayList containing Attributes class Attribute{ private int id; public string getID(){
ArrayList<String> emplist = new ArrayList<String>(); //Inside the array I add list of employee that
ArrayList<String> myArr = new ArrayList<String>(); then add some stuff to it myArr.add(Hello); myArr.add(Testing); myArr.add(Testing
I have an ArrayList of type GeoPoint. private List<GeoPoint> points = new ArrayList<GeoPoint>(); I
ArrayList<String> newArray = new ArrayList<String>(); newArray = urlList.getUrl(); for( int i = 0 ;
I have this arraylist: ArrayList ftd = new ArrayList(); ftd.Add(new string[]{ foo1.txt, 01.01.2011 });

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.