473,382 Members | 1,247 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,382 software developers and data experts.

Javascript Functions Back Slash!

Can someone tell me how do i find the last occurrence of the "\"
character in a file name.

retVal = "\data\sheet\file.gif"
lastPos = retVal.lastIndexOf("\",0);
This code keeps erroring !!!

Thanks..
Jul 23 '05 #1
4 1802
> Can someone tell me how do i find the last occurrence of the "\"
character in a file name.

retVal = "\data\sheet\file.gif"
lastPos = retVal.lastIndexOf("\",0);
This code keeps erroring !!!


the lastPos is correct. The problem is in the first statement.

The \ is the symbol for escaping. Supose you want to put
"starbuck's" in a string using single quotes to surround it.
This is impossible to do:

s = 'starbuck's'

Will error, and you can see why. So you have the escape the character.

s = 'starbuck\'s'

Escaping only works to create certain special characters for exampple:

\" = "
\' = '
\n = enter
\t = tab
\\ = \

You should be able to figure out the rest.

Good luck,
Vincent
Jul 23 '05 #2
ad***********@hotmail.com wrote in message news:<84**************************@posting.google. com>...
Can someone tell me how do i find the last occurrence of the "\"
character in a file name.

retVal = "\data\sheet\file.gif"
lastPos = retVal.lastIndexOf("\",0);
This code keeps erroring !!!

Thanks..


While I do not know where you got the file specification from, you are
using the IE proprietary format for the file name.

The internet format would be:

retVal = "/data/sheet/file.gif"

This format is supported by all web browsers.

Robert
Jul 23 '05 #3
ad***********@hotmail.com wrote:
Can someone tell me how do i find the last occurrence of the "\"
character in a file name.

retVal = "\data\sheet\file.gif"
lastPos = retVal.lastIndexOf("\",0);
This code keeps erroring !!!


Your Exclamation Mark key is borken. [psf 2.3]

Firstly, "Does not work" is a useless error description. [psf 4.11]
Read the FAQ.

Secondly, "\" is the escape character in string literals, use

var retVal = "\\data\\sheet\\file.gif";
var lastPos = retVal.lastIndexOf("\\");

instead. However, you should thirdly pay attention to Robert's comment.
PointedEars
Jul 23 '05 #4
Thomas 'PointedEars' Lahn wrote on 26 jun 2004 in comp.lang.javascript:
Your Exclamation Mark key is borken. [psf 2.3]


Town in Germany, should be with a capital B?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #5

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

Similar topics

5
by: Treetop | last post by:
I have noticed with various codes that the slashes are not consistent. Is there a reason for this. For example </td> </\td> <\/td> <td /> what is the difference with these tags?
5
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
7
by: Trvl Orm | last post by:
I am working with 2 frames, Left and Right and the main code is in the left frame, which has been attached. Can someone please help me with this code. I am new to JavaScript and can't figure it...
5
by: Lucian Sandor | last post by:
Hello everyone, While I'm a newbie here, I a not new to google, so please don't send me back, it would be useless. First of all I have to specify I am working on a Blogger.com template, therefore...
5
by: Tony Strazzeri | last post by:
Hi all, I a fairly new to html and Javascripting. I have been trying to write some code to hide my email address from spam harvesters. I copied the code from various web examples and modified...
10
by: JS | last post by:
I have a rather long JavaScript in my <HEAD> </HEAD> part. I would like to put this javaScript in another file and then just include it instead. Is that possible and what should files containing...
3
by: Liquidchild | last post by:
Not sure if this is the correct group, but... I have the following jsp page, basically i want to append some text to the username before the form is submitted, is this possible? Thanks S. ...
6
by: drec | last post by:
I am just learning Javascript and I would like to create a basic form that gives me two options. This will be using either checkbox or radio input type, however I would like the second option to...
1
by: Kberg | last post by:
In case anyone is interested, this is how I solved the problem of replacing a back slash with a forward slash (as in being able to access a document on a file share on an intranet via a browser) ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.