4 Replies Latest reply on Jun 5, 2008 9:12 AM by fermp

    Can you split with \ ?

    fermp Level 1
      Hi guys,

      I know I'm missing something simple here but I can't figure it out. Basically what I'm trying to do is:

      var filePath = "C:\Documents and Settings\Krishna\Desktop\chooseFiles.jpg";
      _global.myName_array = filePath.split("\\");
      trace(_global.myName_array);

      But when I do that I get:
      C:,ocuments and Settings,rishna,esktop,hooseFiles.jpg

      So its lopping off the first letter of each split.

      Anybody have any ideas how to do this correctly?

      Thanks
        • 1. Re: Can you split with \ ?
          whodeee05 Level 1
          I think it is because you are using "\\", when you should be using "\". have you tried that?
          • 2. Can you split with \ ?
            fermp Level 1
            quote:

            Originally posted by: whodeee05
            I think it is because you are using "\\", when you should be using "\". have you tried that?


            Yes. What seems to be the issue is when you use \ in flash it would clear a special character. For instance if you wanted to put quotes in a variable you'd have to do something like this:

            var specialChar = "\"hello\"";
            trace(specialChar);

            which would trace:
            "hello"

            So if I just used the "\" I would get an error because it would "clear" the last "
            • 3. Re: Can you split with \ ?
              Level 7
              Your backslashes in your string literal need to be escaped.

              var filePath = "C:\\Documents and
              Settings\\Krishna\\Desktop\\chooseFiles.jpg";

              • 4. Can you split with \ ?
                fermp Level 1
                quote:

                Originally posted by: Newsgroup User
                Your backslashes in your string literal need to be escaped.

                var filePath = "C:\\Documents and
                Settings\\Krishna\\Desktop\\chooseFiles.jpg";




                Since I was reading this string in from mProjector chooseFile I didn't have that choice (I think) However I think it was just a bug in the Flash trace window since when I used it in my final application it worked fine. Go figure.

                Thanks for all your help guys