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

  • Home
  • SEARCH
  • 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 448161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:38:31+00:00 2026-05-12T21:38:31+00:00

I am trying to import a file in from my clients custom software. The

  • 0

I am trying to import a file in from my clients custom software. The file is basically a csv file with some custom escape characters in it. I am reading in the file line by line, then splitting each line into a string[]. I am then assigning each each element to a field in my custom object. For example:

Person.Name = line[0];
Person.Age = line[1];
Person.Height = line[2];

etc. The problem is, that some of the files I am importing are from an older version of the app and do not contain all the fields. So this line

Person.Height = line[2];

errors out because line.Length = 2 instead of 3.

Is there a “clean” way of solving this issue? I’ve gotten around it now by writing an if statement before each assignment to make sure the line[x] is valid, but that just seems kludgy to me.

  • 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-12T21:38:32+00:00Added an answer on May 12, 2026 at 9:38 pm

    I’ve got a couple suggestions, assuming you aren’t parsing huge CSVs where every drop of performance counts.

    One approach I use is to have a step before you actually start working with the data where you ensure that the file is consistently formatted. In your case, that would mean scanning each row to determine if all the columns are present and if not, inserting default values for the missing data.

    This can help keep your “cleanup” code separate from your data processing. This actually takes a little more coding and would be slower from a performance perspective (since you’re essentially parsing the file twice), but could help make your code a little easier to read and debug since you are breaking it into two separate activities.

    An alternative would be to use a third-party library like LINQtoCSV to take care of marking “nullable” columns for you. Then you can refer to columns as named properties instead of by index.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to load a default set of data from a csv file into
I am trying to import an excel file using asp.net and C#. I found
I'm trying to use Ruby's csv module to import the records contained in a
I've been trying to pass my login and password from Python script to the
I am trying to open this file in java and i want to know
Hello I been trying to find this memory leak for a while now and
I have been trying to learn Python for a while now. By chance, I
I've been researching how to do this and I can't figure out what I
We have a Joomla website which we want to copy over to another host
I am new to iPhone development. I have two views named pickerviewcontroller and secondviewcontroller

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.