A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: cant use the backslash symbol "\" in my code

  1. #1
    Senior Member
    Join Date
    Mar 2001
    Posts
    527

    cant use the backslash symbol "\" in my code

    HI all

    i have a line of code

    countVar=myVar.lastIndexOf("\");

    but i am not allowed to export the movie,

    if i change the "\" to anything else the the movie is fine -

    why is this, i need to use the "\" symbol as i am cutting up a string of a file path.

    can i use anything else instead ??


    many thanks in advance,

    gilesb

  2. #2
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    \ is used as an escape character, for example you can use " inside a string like this,

    var welcome = "someone says \"hello\"";

    or a new line in some text like this,

    var myString = "hello\nworld"; // adds a new line between words

    In order to use the \ as a regular character in the string you need to escape it using another \

    var myString = "something\\something else";
    trace(myString.length); // the \\ only counts as a single character
    trace(myString.indexOf("\\");

    hope this helps

  3. #3
    the '\' character is used to escape other non-printable characters such as the newline '\n' carraige return '\r' null byte '\0' and so on. In order to use it, you must escape it, so the \ character is entered as '\\'.

  4. #4
    you're too fast for me catbert

  5. #5
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222

  6. #6
    Senior Member
    Join Date
    Mar 2001
    Posts
    527
    Hi chaps

    many thanks for that

    gilesb

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center