473,669 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,po s); // Extract the name
var value = pairs[i].substring(pos+ 1); // Extract the value
value = decodeURICompon ent(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 13688
* Gene Kelley wrote in comp.lang.javas cript:
>value.replac e(/ /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****@h oehrmann.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
4112
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 one word is keyed in. If two words are keyed in, it separates them with a plus sign. I have tried using the split command to parse out the data but that function does not recognize the plus sign. Any help here? I know some of you folks have...
2
5845
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 ExteriorCommands could not find it. It returned the value: '$executed'.", "CommandRenderAllActionsInAnArray");
4
1859
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 want to keep the text contained in the brackets and nothing else.
2
1813
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 this to convert these characters back to "<" and ">" signs. Please tell me asap.
1
2748
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 cases today. Looking a little deeper, it seems that when encrypted one value had a + in it. When this was picked up at the receiving page, I see the + turns into a space, which then throws off the decryption. Is a + an illegal character for a...
6
6102
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 more minutes. 'REMOVE DUBLICATED VALUE FROM ARRAY +++++++++++++++++ Dim col As New Scripting.Dictionary Dim ii As Integer = 0
3
6629
by: Mateo | last post by:
(As.Net 1.1 framework!) Hi! So, I have problem as described in subject. Here is source code:
4
4191
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 hyphens, etc etc. However I am struggling to remove pound (£) signs. Is there something different that I need to do for currency symbols? Any help would be appreciated! Thanks
0
2513
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 encoded in the source that I am trying to extract with the WebRequest and WebResponse objects. The page is using a charset of iso-8859-1 which I think is the problem as my object is using UTF-8. I have created two test pages one using UTF-8 the...
0
8383
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8894
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8803
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2029
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1787
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.