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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:55:36+00:00 2026-05-26T23:55:36+00:00

Suppose I have an array of string like following: str_arr=[10$, 10$ I am a

  • 0

Suppose I have an array of string like following:

str_arr=["10$", "10$ I am a student","10$Good","10$ Nice weekend!"]

I would like to re-organize the array element value in the way that, in each element of the array , if there is(are) white space(s) after 10$ sign, then, combine the 10$ with the following word.

That’s generating a new array like following:

str_arr=["10$", "10$I am a student","10$Good","10$Nice weekend!"]

What I tried to do is like following:

str_arra.map{|elem| 
     # not sure how to do here, 
     #split and check then combine again?
      if elem.size>1
         words=elem.split()
         if words[0]=='10$'
             #not sure how to do here
         end
      elsif elem.size==1
         elem
      end


 }

but not sure how to generate the new array … and the code above seems verbose…

P.S. it is possible that there are multiple white-spaces after 10$, then comes a word

  • 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-26T23:55:37+00:00Added an answer on May 26, 2026 at 11:55 pm

    If you only have those cases, the following should do the trick:

    ["$ abc", "$str"].map {|v, k| v.sub(/\$ +/, '$')}
    

    Here’s an example: http://codepad.org/XHeo7E8B

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

Sidebar

Related Questions

Suppose I have two arrays like the following: $arr2 = array(array(first, second), array(third, fourth));
Suppose I have a string of 123456789 . I would like to split this
Suppose I have an array that mimics a database table. Each array element represents
Suppose I have an array like this: $array = array(a,b,c,d,a,a); and I want to
Suppose that I have a 2D array (matrix) in Java like this... int[][] MyMat
Suppose we have the Java code: Object arr = Array.newInstance(Array.class, 5); Would that run?
Suppose I have an integer array like this: {5,3,5,4,2} and I have a method
suppose I have a class like class ABC { int ID; public string Name;
Suppose I have an object that looks like: public class Obj { String foo;
Suppose I have two arrays: val ar1 = Array[String](1, 2, 3) val ar2 =

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.