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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:46:38+00:00 2026-05-18T22:46:38+00:00

In my app, I have a textfield in which the user enters something like

  • 0

In my app, I have a textfield in which the user enters something like this

"1,2,3,4"

which gets stored to the database. Now, when I want to use the inner numbers, i have two options:

"1,2,3,4".split(',')

OR

string.scan(/\d+/) do |x|
    a << x
end

Both ways i get an array like

 ["1","2","3","4"] 

and then i can use the numbers by calling to_i on each one of them.
Is there a better way of doing this, that converts

"1,2,3" to [1,2,3] and not ["1","2","3"]
  • 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-18T22:46:39+00:00Added an answer on May 18, 2026 at 10:46 pm
    str.split(",").map {|i| i.to_i}
    

    but the idea is same to you….

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

Sidebar

Related Questions

Hi have a products model in my Rails 3.1 app which looked like this:
I have a calculator app in which I have a textfield in which if
So I have 4 text fields in which a user can use to narrow
I have a facebook app which I'd like to test using Watir. The problem
Have an ASP.NET MVC3 app with model validation using FluentValidation . User enters some
I have a countdown TextField which I like to update every minute automatically in
I have a textfield which fires an event in a web app, but I'd
In my iPad app I have two textfields. One displays the normal, default textfield
Possible Duplicate: Email validation on textField in iPhone sdk I have an app in
My app have a background image that fills the screen. I'd like to display

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.