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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:13:41+00:00 2026-05-20T12:13:41+00:00

I have scoured the Internet for an answer to this. I have an array

  • 0

I have scoured the Internet for an answer to this. I have an array of strings that looks something like this:

[0] Cinnamon+Chocolate+Twists
[1] 3.25+Ounce+Croissant 

I need all the ‘+’ characters removed from these strings, and a space inserted instead. The following code does not work:

nameProduct[1] = nameProduct[1].replace("+"," ");

I have tried several variations of the .replace method, but no luck. Any ideas?

  • 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-20T12:13:42+00:00Added an answer on May 20, 2026 at 12:13 pm

    You have to use regular expression with the global flag to replace every occurrence of the character (yes, JavaScript behaves weird in this aspect (or let’s say unexpected, depending from which other language you come)):

    nameProduct[1] = nameProduct[1].replace(/\+/g," ");
    

    Use a loop to do this for every element.

    MDC – replace documentation


    Update:

    Don’t use document.write to create HTML. Your code needs a lot of refactoring but this beyond this question. The data is processed correctly, but the generated HTML is not:

    <input type="text" size="40" name="Product1401" value="Cinnamon" chocolate="" twists="" readonly="">
    

    You see, you have problems with the quotes. The other parts of the text are recognized as attributes.

    A slightly improved version would be (just this part):

    var nameProduct = hashes[i].split('=');
    var tr = document.createElement('tr');
    var td = document.createElement('td');
    var input = document.createElement('input');
    
    input.type = "text";
    input.size = 40;
    input.name = nameProduct[0]      
    nameProduct[1] = nameProduct[1].replace(/%/g, '');
    nameProduct[1] = nameProduct[1].replace(/2C/g, '');
    nameProduct[1] = nameProduct[1].replace(/2F/g, '');
    nameProduct[1] = nameProduct[1].replace(/28/g, '');
    nameProduct[1] = nameProduct[1].replace(/29/g, '');
    nameProduct[1] = nameProduct[1].replace(/\+/g, " ");
    
    input.value = nameProduct[1];
    input.readOnly = true;
    
    td.appendChild(input);
    tr.appendChild(td);
    document.getElementById('gradient-style').tBodies[0].appendChild(tr);
    

    DEMO

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

Sidebar

Related Questions

I've scoured the internet and my own intellect to answer this basic question, however,
I have scoured the internet looking for a solution to this and I am
I have scoured the internet to find which CMS's run on CloudSites and the
I have scoured the web for a decent explanation of the routing syntax in
Have you managed to get Aptana Studio debugging to work? I tried following this,
So I have learned that that the Microsoft.Jet.OLEDB.4.0 data provider for querying data sources
I've scoured the Internet but my search-foo must not work if it's out there
Forgive me if this has been asked before, but I assure you I've scoured
This is my RSS template that I load into my simplexml object. I want
For some reason i can't seem to get this right ok i have 2

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.