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 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 currently trying to import about 10000 rows (from a CSV file) into an
I'm trying to import a matrix (about 80.000 rows) from a csv file to
I am trying to import a txt/csv file into my postgres database from php
I am trying to import data from excel file (.xlsx) into sql database, my
I’m trying to import fixed width data from text file into SQL Server Express
i'm trying to import records from a mdb file to sql server 2008. i
I am trying to import a csv file to insert data into an existing
I am trying to send some commands from a server to about 50 clients
I'm trying to download file with Python using IE: from win32com.client import DispatchWithEvents class
I've been having some trouble trying to send a file from a server to

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.