Javascript Functions Back Slash!

Discussion in 'Javascript' started by adam_a_knight@hotmail.com, Jun 18, 2004.

  1. Guest

    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..
     
    , Jun 18, 2004
    #1
    1. Advertising

  2. > 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
     
    Vincent van Beveren, Jun 18, 2004
    #2
    1. Advertising

  3. Robert Guest

    wrote in message news:<>...
    > 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
     
    Robert, Jun 18, 2004
    #3
  4. 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
     
    Thomas 'PointedEars' Lahn, Jun 26, 2004
    #4
  5. Evertjan. Guest

    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)
     
    Evertjan., Jun 26, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian J. Sayatovic
    Replies:
    1
    Views:
    984
    Chris Uppal
    Jun 25, 2004
  2. andrew
    Replies:
    7
    Views:
    1,799
    Hillbilly
    Oct 9, 2008
  3. Chris Rebert

    Re: string replace for back slash

    Chris Rebert, Feb 5, 2009, in forum: Python
    Replies:
    0
    Views:
    421
    Chris Rebert
    Feb 5, 2009
  4. Replies:
    0
    Views:
    2,030
  5. Kberg
    Replies:
    1
    Views:
    172
    Martin Honnen
    Dec 26, 2006
Loading...

Share This Page