substr() method in JavaScript

Results 1 to 3 of 3

Thread: substr() method in JavaScript

  1. #1
    Join Date
    Dec 1969

    Default substr() method in JavaScript

    Hello all,<BR>I need to pull the page string only(search.asp) from the URL<BR><BR><BR>The problem I am having is that the URL may or may not have a querystring. <BR>I have tried the following:<BR><BR>var hreff = location.href;<BR>var strHref = hreff.substr(hreff.lastIndexOf("/")+1,hreff.lastIndexOf(".asp"));<BR>alert(strHref) ;<BR><BR>this gives me search.asp if no querystring but if I have a querystring I get search.asp?searchstring=sdfjskd..... etc<BR>Any Ideas?<BR>TIA!

  2. #2
    Join Date
    Dec 1969

    Default You're using it wrong

    stringvar.substr(start [, length ]) <BR><BR>Your telling the length to go as far as the .asp. Say that&#039;s at char 40.<BR><BR>You&#039;re starting at X point, and going all the way in.

  3. #3
    Join Date
    Dec 1969

    Default You want substring, not substr

    substring( start, end+1 )<BR><BR>A subtle difference between substring and substr, but an important one.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts