Javascript Functions Back Slash!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • adam_a_knight@hotmail.com

    #1

    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\fi le.gif"
    lastPos = retVal.lastInde xOf("\",0);
    This code keeps erroring !!!

    Thanks..
  • Vincent van Beveren

    #2
    Re: Javascript Functions Back Slash!

    > Can someone tell me how do i find the last occurrence of the "\"[color=blue]
    > character in a file name.
    >
    > retVal = "\data\sheet\fi le.gif"
    > lastPos = retVal.lastInde xOf("\",0);
    > This code keeps erroring !!![/color]

    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


    Comment

    • Robert

      #3
      Re: Javascript Functions Back Slash!

      adam_a_knight@h otmail.com wrote in message news:<84fdae32. 0406180056.7c4d 0be0@posting.go ogle.com>...[color=blue]
      > Can someone tell me how do i find the last occurrence of the "\"
      > character in a file name.
      >
      > retVal = "\data\sheet\fi le.gif"
      > lastPos = retVal.lastInde xOf("\",0);
      > This code keeps erroring !!!
      >
      > Thanks..[/color]

      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

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Javascript Functions Back Slash!

        adam_a_knight@h otmail.com wrote:[color=blue]
        > Can someone tell me how do i find the last occurrence of the "\"
        > character in a file name.
        >
        > retVal = "\data\sheet\fi le.gif"
        > lastPos = retVal.lastInde xOf("\",0);
        > This code keeps erroring !!![/color]

        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.lastInde xOf("\\");

        instead. However, you should thirdly pay attention to Robert's comment.


        PointedEars

        Comment

        • Evertjan.

          #5
          Re: Javascript Functions Back Slash!

          Thomas 'PointedEars' Lahn wrote on 26 jun 2004 in comp.lang.javas cript:[color=blue]
          > Your Exclamation Mark key is borken. [psf 2.3][/color]

          Town in Germany, should be with a capital B?

          --
          Evertjan.
          The Netherlands.
          (Please change the x'es to dots in my emailaddress)

          Comment

          Working...