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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:27:04+00:00 2026-05-26T07:27:04+00:00

My Rails3 app parses user-uploaded CSV files. As can be expected, users upload tab-separated

  • 0

My Rails3 app parses user-uploaded CSV files.
As can be expected, users upload tab-separated AND comma-separated files.
I want to support both.

My code:

input = CSV.read(uploaded_io.tempfile, { encoding: "UTF-8", :col_sep => "\t"})

QUESTION:How to change it to support commas too?

FasterCSV’s doc describes col_sep as The String placed between each field. so :col_sep => ",\t" won’t work.

Note: All data inside are integers or identifiers, so the probability of someone using \t or , within the content (not a delimiter) is zero. So usage of the two different delimiters in the same file is not something I expressly want to prevent.

  • 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-26T07:27:05+00:00Added an answer on May 26, 2026 at 7:27 am

    Solution 1:

    One simple way to do it is to let the user select with a drop-down which separator they use in their CSV file, and then you just set that value in the CSV.read() call. But I guess you want it automatic. 🙂

    Solution 2:

    You can read-in the first line of the CSV file with regular File.read() and analyze it by matching the first line against /,/ and then against /\t/ … depending on which RegExp matches, you select the separator in the CSV.read() call to the according (single) separator. Then you read in the file with CSV.read(..., :col_sep => single_separator ) accordingly.

    But Beware:

    At first it looks nice and elegant to want to use ",\t" as the separator in the method call to allow both — but please note this would introduce a possible nasty bug!

    If a CVS file would contain both tabs and commas by accident or by chance … what do you do then?
    Separate on both? How can you be sure? I think that would be a mistake, because CSV separators don’t appear “mixed” like this in regular CSV files — it’s always either ',' or "\t"

    So I think you should not use ",\t" — that could be causing huge problems, and that’s probably the reason why they did not implement / allow the col_sep option to accept a RegExp.

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

Sidebar

Related Questions

I want to allow a user of my web-app to be able to post
My Rails-app has a sign in box with a remember me checkbox. Users who
I'm writing a reports dashboard for a rails app. The dashboard is for user
I want to perform a search query from my rails app, which uses the
My Basic Goal A Rails app that can load new content via Ajax while
I have a simple problem. I want to delete all app request sent via
I want my Rails App to parse external websites for a trackback URL but
I want my rails app to accept dates for a date field in the
I would like for a user within my ruby on rails app to be
I'm trying to test for granted permissions by Facebook users in a rails app.

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.