Skip to main content
Inspiring
June 4, 2008
Question

Can you split with \ ?

  • June 4, 2008
  • 2 replies
  • 335 views
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
This topic has been closed for replies.

2 replies

Inspiring
June 4, 2008
Your backslashes in your string literal need to be escaped.

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

fermpAuthor
Inspiring
June 5, 2008
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
Participating Frequently
June 4, 2008
I think it is because you are using "\\", when you should be using "\". have you tried that?
fermpAuthor
Inspiring
June 4, 2008
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 "