473,327 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

LastIndexOf error

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
6 2869
<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
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
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
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
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
yup all that time it was the lowercase L...

Jscript is so sensitive :P

tx guys

Jan 28 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matt | last post by:
In test() method: var path="C:\test\hello.txt"; //returns -1 for path.lastIndexOf("\\"). why?? var pos=path.lastIndexOf("\\"); //return -1 But in showFile() method: We are able to get the...
2
by: Ivar | last post by:
Hi, string s = "aXXa"; Console.WriteLine(s.LastIndexOf("XX",0)); Console.WriteLine(s.LastIndexOf("XX")); Console.WriteLine(s.IndexOf("XX",0)); Console.WriteLine(s.IndexOf("XX")); Result:...
9
by: sklett | last post by:
string url = http://localhost/subPath/Default.aspx; k = url.LastIndexOf("/", 0, url.Length); This throws an exception: Count must be positive and count must refer to a location within the...
3
by: Terry Olsen | last post by:
I have a string that is approximately 600 characters. I need to divide up the string into 400 character chunks. I'm having trouble with using LastIndexOf. The following code returns a value of...
0
by: ccshine via DotNetMonster.com | last post by:
I'm working on an app that implements a Structure to store a recordset in an ArrayList. I used this setup to bind to a DataGrid and it worked out so well, I thought it might be a better solution...
0
by: ccshine | last post by:
I'm working on an app that implements a Structure to store a recordset in an ArrayList. I used this setup to bind to a DataGrid and it worked out so well, I thought it might be a better solution...
3
by: =?Utf-8?B?dmluYXk=?= | last post by:
I am trying to check LastIndexOf "\" in a File Path, if it not there i want to append a "\" for some reason it throws error? int index = filePath.LastIndexOf("\"); Any suggestions... --
9
by: senfo | last post by:
I realize it's Friday and I'm probably already on vacation for the remainder of the day; but, I have a really, really stupid question. Is there a bug in the .NET 2.0 Framework in regards to the...
1
by: darrel | last post by:
This line: response.write(mystring.LastIndexOf("\").ToString) gives me this error: mystring.LastIndexOf" to type 'Long' is not valid. Microsoft.VisualBasic why?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.