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 8392729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:35:27+00:00 2026-06-09T19:35:27+00:00

I have read in some CSV values, line by line, that have the following

  • 0

I have read in some CSV values, line by line, that have the following format:

30: "NY", 41: "JOHN S.", 36: "HAMPTON", 42: "123 Road Street, NY", 68: "Y"

I need to break this down to something like the following in order to parse these items further:

30: "NY"

41: "JOHN S."

36: "HAMPTON"

42: "123 Road Street, NY" (note the comma)

...

I’m using the FileHelper library, but it seems to like reading things in line-by-line, despite me wanting it split by it’s delimited , commas.

I have the record class:

[DelimitedRecord(",")]
class BoxRecord
{
    public String record;
}

And I retrieve what I hoped would be several objects in an array via the following, but it just returns me the original line:

DelimitedFileEngine engine = new DelimitedFileEngine(typeof(BoxRecord));
BoxRecord[] boxes = (BoxRecord[])engine.ReadString(boxLine);

What I want boxes[].record to contain:

30: "NY"

41: "JOHN S."

36: "HAMPTON"

42: "123 Road Street, NY"

...

What it actually contains:

30: "NY", 41: "JOHN S.", 36: "HAMPTON", 42: "123 Road Street, NY", 68: "Y"

  • 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-06-09T19:35:29+00:00Added an answer on June 9, 2026 at 7:35 pm

    After getting the line, you can break the line based on below linq to get what you want:

    string input = "30: \"NY\", 41: \"JOHN S.\", " +
       "36: \"HAMPTON\", 42: \"123 Road Street, NY\", 68: \"Y\"";
    
    var tempList = input.Split('\"').ToList();
    
    var result = Enumerable.Range(0, tempList.Count/2)
        .Select(i => string.Join(": "
            , tempList[2*i].Split(new[] { ',', ':' })
               .Single(ss => !string.IsNullOrWhiteSpace(ss))
    
            , tempList[2*i + 1]));
    

    Update: Seem it’s interesting for me, this code is to handle the case as your comment:

    var tempList1 = input.Split(':').ToList();
    
    var tempList2 = tempList1.SelectMany((s, index) =>
     {
         if (index == 0 || index == tempList1.Count - 1)
             return new List<string>() { s };
    
         var subList = s.Split(',');
         return new List<string>
               { 
                    string.Concat(subList.Take(subList.Length - 1)),
                    subList.Last()
               };
     }).ToList();
    
    var result = Enumerable.Range(0, tempList2.Count / 2)
             .Select(i => string.Join(": ", tempList2[2 * i], tempList2[2 * i + 1]));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strange problem: I have a CSV file that I read correctly
I have a ruby script which will read data from some CSV file and
I have a String Array which is contain dates that read from a CSV
I have some large csv files (1.5gb each) where I need to replace specific
I am reading a CSV file and have some values like field 1 field
I have following sample CSV file rc,u,s,ui,gh m,1,8,0,12 n,3,0,0,7 d,1,1,8,0 I want to read
I have a csv file where some of the numerical values are expressed as
I have csv file having some address data mostly in Finnish language. I need
Possible Duplicate: How to read a CSV line with "? I have seen a
I have this quite big CSV file (15 Gb) and I need to read

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.