LastIndexOf error

T

treasonftg

What am i doing wrong here?


var URL = String(RS("FileName"));
var ID = URL.LastIndexOf("\\");
ID = URL.substr(ID);

RS is a recordset from a database that shows a FilePath, I left out the
DB code..
for example RS("FileName") might equal C:\test\temp.txt

I want to extract the filename (temp.txt)

It keep erroring saying Error:Object doesn't support this property or
method
at the lastindexofline...

Any Ideas?
 
M

McKirahan

What am i doing wrong here?


var URL = String(RS("FileName"));
var ID = URL.LastIndexOf("\\");
ID = URL.substr(ID);

RS is a recordset from a database that shows a FilePath, I left out the
DB code..
for example RS("FileName") might equal C:\test\temp.txt

I want to extract the filename (temp.txt)

It keep erroring saying Error:Object doesn't support this property or
method
at the lastindexofline...

Any Ideas?

..lastIndexOf() -- lowercase "L"
 
R

RobG

McKirahan said:
.lastIndexOf() -- lowercase "L"

I think you can take that as a typo. The problem is that when \t is
parsed it is treated as a single character and interpreted as a tab
(ASCII 9) and not a backslash (ASCII 92) followed by a 't'.

The backslash quotes whatever follows it, it isn't treated as a single
character.

For example:

var x = "\t";
alert(x.length) // shows 1, not 2.


I don't know how to fix it without modifying the original string to make
all '\' into '\\'. There must be a solution though...
 
R

Randy Webb

RobG said the following on 1/24/2006 11:48 PM:
I think you can take that as a typo.


No sir, the typo was the source of the error :)
The problem is that when \t is parsed it is treated as a single
character and interpreted as a tab (ASCII 9) and not a backslash
(ASCII 92) followed by a 't'.

That won't cause an "Object doesn't support...." error though. It is in
the string itself. It will cause erroneous results at the end though.
The backslash quotes whatever follows it, it isn't treated as a single
character.

Only if the character following it has meaning in JS.

alert('This is \s text');

What will it do with the \s?
For example:

var x = "\t";
alert(x.length) // shows 1, not 2.


I don't know how to fix it without modifying the original string to make
all '\' into '\\'. There must be a solution though...

There's not in JS. It has been hunted for at least 6 years though :)
 
R

RobG

Randy said:
RobG said the following on 1/24/2006 11:48 PM:
McKirahan wrote: [...]
.lastIndexOf() -- lowercase "L"

I think you can take that as a typo.



No sir, the typo was the source of the error :)
The problem is that when \t is parsed it is treated as a single
character and interpreted as a tab (ASCII 9) and not a backslash
(ASCII 92) followed by a 't'.


That won't cause an "Object doesn't support...." error though. It is in
the string itself. It will cause erroneous results at the end though.

Doh... :-x


[...]
There's not in JS. It has been hunted for at least 6 years though :)

So I guess the answer to the OP is that the (server?) routine that
creates the record set should replace all instances of '\' with '\\'
before the set is used in the script.
 
L

Lasse Reichstein Nielsen

I think you can take that as a typo. The problem is that when \t is
parsed it is treated as a single character and interpreted as a tab
(ASCII 9) and not a backslash (ASCII 92) followed by a 't'.

But it shouldn't be parsed, if it comes from a database as a string
value. Only Javascript literals are parsed in this way.

While it is possible that the string is sent in a way that is
converted to a string value using "eval", and not correctly escaped
for the transfer, my guess is that it is not the case here.

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top