Re: 2 Qs re JS scripting



Dave,
Thank you for this little tutorial. I am trying to learn more about regular
expressions so every bit helps

I think I am correct in saying
str.replace(/%20|\+/g," "))
translates in English as
Replace every occurrence in str of either %20 or + with blank

No need to reply if I am right
:-))
--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au

Dave Anderson wrote:
> Trevor L. wrote:
>> function qsobj(parm)
>> {
>> var qstring = document.location.search.substring(1)
>> var qpairs = qstring.split("&")
>> var qvbl = qpairs[parm].split("=")
>> return unescape(qvbl[1].replace("%20"," ").replace("+"," "))
>> }
>> I found this on the web somewhere and refined it a little.
>> If any one can make it more succinct, would be grateful
>
> If the first argument of String.replace() is a string, only the first
> match will be replaced. If you use a regular expression, you can make
> it replace all instances:
>
> String.replace(/%20|\+/g," ")
>
> Now, you may have been fooled in the past into thinking you got a
> global replacement on %20. But Internet Explorer treats that value as
> " ". If you examine the problem in ASP, however, you will see how
> *JScript* handles it:
> <%@ Language=JScript %><%
> var str = "this+is+a%20test%20sentence"
> Response.Write(str.replace("%20"," ").replace("+"," "))
> %>
>
> The output?
>
> this is+a test%20sentence
>
> Using the regular expression:
>
> Response.Write(str.replace(/%20|\+/g," "))
>
> Result: this is a test sentence
>
>
>
>> The replace of %20 and + may not be necessary in all
>> cases. I understood that some browsers use + in place
>> of blanks
>
> I believe the + always results from form submission (with method
> GET), while %20 is generated by the URI escaping mechanism. Most
> typically, the mechanism is used for HREF attributes and when typing
> an address into the browser's location bar.
>
>
> --
> Dave Anderson
>
> Unsolicited commercial email will be read at a cost of $500 per
> message. Use of this email address implies consent to these terms.
> Please do not contact me directly or ask me to contact you directly
> for assistance. If your question is worth asking, it's worth posting.


.



Relevant Pages

  • Re: McAfees Naming Convention of Computer Viruses, Worms and Trojans
    ... I have been a regular of 'alt.comp.virus' for over 10 years and a lurker before that. ... Dave ... |> | Here's Symantec's description of the naming issue: ... |> | The most current formulation of the CARO conventions seems to be the ...
    (microsoft.public.security.virus)
  • Re: The Emmys Thread
    ... I don't enjoying hearing the same jokes repeated as some here do because I think it's an insult to regular viewers. ... Maybe it's unfair to compare Dave to Carson, but to me, that's who he seems closest to. ... But he did a nightly show with a topical monologue and I don't remember ever noticing him repeating the exact same joke, word-for-word, several nights in a row. ...
    (alt.fan.letterman)
  • Re: The Emmys Thread
    ... I've been watching Dave regularly since his second year at NBC. ... the same jokes repeated as some here do because I think it's an insult to ... Johnny had a few regular themes; "How hot was it?", Ed's drinking, Doc's ... But he did a nightly show with a topical monologue ...
    (alt.fan.letterman)
  • Re: Rob update
    ... and lack of privacy- we didn't have it as bad but when Dave first came ... The intake nurse seems to think that I deliberately poisoned ... is that me giving him his meds was far more regular than him taking his ... You should have seen her temper tantrum when the night shift gave ...
    (rec.pets.cats.anecdotes)
  • Re: Simple? rollover
    ... I would use the CSS2 solution, which makes it a bonus feature for non-IE ... Dave Anderson ... Unsolicited commercial email will be read at a cost of $500 per message. ... If your question is worth asking, ...
    (microsoft.public.scripting.jscript)