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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:06:26+00:00 2026-05-18T20:06:26+00:00

When given a list of comma separated values like 3, asdf, *#, 1212.3 ,

  • 0

When given a list of comma separated values like 3, asdf, *#, 1212.3, I would like to extract each of these values, not including the comma, so I would have a value list like [3, "asdf", "*#", 1212.3] (not as a textual representation like that, but as an array of ‘hits’). How would I do this?

  • 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-18T20:06:26+00:00Added an answer on May 18, 2026 at 8:06 pm

    First off, if you are dealing with CSV files, don’t use regex or your own parser. Basically when you think things are simple they really aren’t, Stop Rolling Your Own CSV Parser.

    Next up, you say that you would like to have an array ([3, “asdf”, “*#”, 1212.3]). This looks to be mixing types and can not be done in a static language. And ultimately is very inefficient even using std.variant. For each parsed value you’d have code like:

    try {
        auto data = to!double(parsedValue);
        auto data2 = to!int(data);
        if(data == data2)
            returnThis = Variant(data2);
        else
            returnThis = Variant(data);
    } catch(ConvException ce) { }
    

    Now if your data is truely separated by some defined set of characters, and isn’t broken into records with new lines, then you can use split(“, “) from std.algorithm. Otherwise use a CSV parser. If you don’t want to follow the standard wrap the parser so the data is what you desire. In your example you have spaces, which are not to be ignored by the CSV format, so call strip() on the output.

    In the article I linked it mentions that what commonly happens is that people will write a parser in its simplest form and not handle the more complicated cases. So when you look for a CSV parser you’ll find many that just don’t cut it. This writing your own parser comes up, which I say is fine just handle all valid CSV files.

    Luckily you don’t need to write your own as I reciently made a CSV Parser for D. Error checking isn’t done currently, I don’t know the best way to report issues such that parsing can be corrected and continue. Usage examples are found in the unittest blocks. You can parse over a struct too:

    struct MyData {
        int a;
        string b;
        string c;
        double d
    }
    
    foreach(data; csv.csv!MyData(str)) // I think I'll need to change the module/function name
        //...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When given a list of comma separated values like 3, asdf, *#, 1212.3 ,
Given a list of urls, I would like to check that each url: Returns
In a certain TABLE, I have a VARTEXT field which includes comma-separated values of
Given a List<int> how to create a comma separated string?
I'm hoping to return a single row with a comma separated list of values
Given a list, how would I select a new list, containing a slice of
I have to write a function, that returns true if a given list is
I have a csv file where each row defines a room in a given
Given a list of locations such as <td>El Cerrito, CA</td> <td>Corvallis, OR</td> <td>Morganton, NC</td>
Given a list ["foo", "bar", "baz"] and an item in the list "bar" ,

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.