By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,067 Members | 1,818 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,067 IT Pros & Developers. It's quick & easy.

LastIndexOf error

P: n/a
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?

Jan 25 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
<tr********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
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"
Jan 25 '06 #2

P: n/a
McKirahan wrote:
<tr********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
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"


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...
--
Rob
Jan 25 '06 #3

P: n/a
RobG said the following on 1/24/2006 11:48 PM:
McKirahan wrote:
<tr********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
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"


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 :)

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 25 '06 #4

P: n/a
Randy Webb wrote:
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
[...]

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 :)


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.
--
Rob
Jan 25 '06 #5

P: n/a
RobG <rg***@iinet.net.au> writes:
<tr********@gmail.com> wrote in message
for example RS("FileName") might equal C:\test\temp.txt
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jan 25 '06 #6

P: n/a
yup all that time it was the lowercase L...

Jscript is so sensitive :P

tx guys

Jan 28 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.