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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:38:47+00:00 2026-05-11T16:38:47+00:00

I have an array like so: [marblecake, also, the, 1337] I would like to

  • 0

I have an array like so:

["marblecake", "also", "the", 1337]

I would like to get back a string which contains each element of the array prefixed by some specified string, then joined together by another specified string. For example,

["marblecake", "also", "the", 1337].join_with_prefix("%", "__")

should result in

# => %marblecake__%also__%the__%1337

How might I do this?

  • 1 1 Answer
  • 1 View
  • 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-11T16:38:47+00:00Added an answer on May 11, 2026 at 4:38 pm

    If your array is in a then this one-liner will do it

    a.map { |k| "%#{k}" }.join("_")
    

    You could easily put this in a function of your own – even add it to the Array class so that you can call it on an array, like in your example.

    Note that the ‘!’ version of map (map!) will modify the array in place – perhaps not your intent.

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

Sidebar

Related Questions

I have an array like [1,1,1,2,4,6,3,3] and I would like to get the list
Lets say I have an array like this: string [] Filelist = ... I
I have byte array as input. I would like to convert that array to
I have a byte array in memory, read from a file. I would like
I have a vector-like class that contains an array of objects of type T
An array is defined of assumed elements like I have array like String[] strArray
How to find whether a string array contains some part of string? I have
I have an array like this, with missing keys: array(2) { [0]=> string(4) Bill
I have an array and filled its values like that: $('#list input:checked').each(function() { deleteRecordIdsStr.push($(this).attr('name'));
I have an array of directories (a search which includes subdirectories). I'd like to

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.