RE: using a variable in variable.lastIndexOf not working properly

by "Cyanide _7" <leo7278(at)hotmail.com>

 Date:  Thu, 13 Jan 2000 04:01:26 CST
 To:  Chucke(at)captura.com
 Cc:  hwg-languages(at)hwg.org
  todo: View Thread, Original
The short answer to my original question was to officially declare
>the variable as a string, since the URL returned wasn't clearly a string 
>and
>Javascript didn't know what to do with it:

actually, your problem was that location is NOT a string, it is an object. 
location.href would have been a string. they REALLY messed up when they 
decided it would be alright to assign a string to the location object and 
have it do the same thing, but it only created poor scripting habits.

>
>var loc_string = document.location;
>s = new String(loc_string);

really not necissary  ^^^

>
>However, I got to digging and came up with a better way to do what I wanted
>to do. Since I want to just remove the first three letters of the path (for
>example, /AB) and replace with a different slash and two-letter pair,
first three? thought you wanted lastIndexOf...

I'm
>using this:
>
><script language="JavaScript">
><!--
>var loc_URL = document.location;
>// gives me the raw URL
>
>var path_string = loc_URL.pathname;
>// gives me a document path, without the http and domain
>
>var length_of_string = path_string.length;
>// returns the length of the path string
>
>var path_substring = path_string.substring(3,length_of_string);
>// returns a new string, removing the first three characters from the first
>string

only needs one line. and substring doesn't need the second argument to say 
"til the end of the string", all it needs is the start  and it goes from 
there. more efficient than declaring three variables:

var path = location.pathname.substring(3);

just try to remember that location is NOT a string, and if you try to modify 
it as such: netscape acts wierd, but IE just errors. and rightly so! - 
Cyanide_7

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA