473,320 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Removing plus signs from URL query string

This has got to be an easy one, but I'm just not getting it.

The following function (below) returns name=value pairs from URL queries
(GET). All is working as expected, but I am trying to figure out how to
remove the + (plus signs) from the values that contain spaces.

I'm trying to use the String Object's replace() method to accomplish this.

This is what I've tried so far along with the results:

value.replace('+', ' ') = first and only first occurrence of + is
replaced

value.replace('+'/g, ' ') = error: "g is not defined"

value.replace(/ /g, ' ') = doesn't replace any + with a space

value.replace(' '/g, ' ') = error: "g is not defined"

value.replace(/' '/g, ' ') = doesn't replace any + with a space

function getArgs() {
var args = new Object();
var query = location.search.substring(1); // Get query string
var pairs = query.split("&"); // Break at ampersand

for(var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf('='); // Look for "name=value"
if (pos == -1) continue; // If not found, skip
var argname = pairs[i].substring(0,pos); // Extract the name
var value = pairs[i].substring(pos+1); // Extract the value
value = decodeURIComponent(value); // Decode it, if needed
value = value.replace(/+/g, ' '); // replace plus with space
args[argname] = value; // Store as a property
}
return args;
}
I'm running out of ideas. ?? Can anyone guide me in the right direction?

Thanks all...
--
------------------------------------
Gene Kelley
Villa Ridge, Missouri, USA
Jun 27 '08 #1
1 13589
* Gene Kelley wrote in comp.lang.javascript:
>value.replace(/ /g, ' ') = doesn't replace any + with a space
Well of course it does not, you are not searching for "+" at all. Use

value.replace(/\+/g, ' ');

instead.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: r0adh0g | last post by:
I am attempting to build a primitive search form on my site. It is searching an Access Database Table and comparing on field in the database to a field passed from the form. Works great if only...
2
by: lkrubner | last post by:
When I had these two lines in my code: if ($executed == "The command didn't exist") { $this->core->error("In CommandRenderAllActionsInAnArray we sought the command '$commandName' but...
4
by: Steve | last post by:
Hi, I have a table which contains records of user access and searches made within an application, this is a sample of the data: response for 101 results from database in 28906 ms I only...
2
by: Renuka | last post by:
Hello, I have to retrive 2 columns from the database which have HTML characters like &lt; &gt; (the less than"<" and greater than sign ">")in their data. Is there any function in C# which can do...
1
by: MattB | last post by:
I'm tightening security on my application by encrypting query strings so someone can't try and guess other valid query string values. This was working well, but I noticed it wasn't working in some...
6
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
3
by: Mateo | last post by:
(As.Net 1.1 framework!) Hi! So, I have problem as described in subject. Here is source code:
4
by: TonyN | last post by:
I have some code to adjust data entered into a web page template to use it in a javascript function. This, amongst other things, will remove start and end spaces, replace the inter-word spaces with...
0
by: RobR2009 | last post by:
I am having trouble with a C# proxy page I am writing which allows me to do cross domain AJAX calls with Javascript. The problem is with certain pages that contain pound signs £ that are not HTML...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.