AS split \
- Started
- Last post
- 4 Responses
- talltyler
Hello,for some reason I cant seem to split a windows path. It has something to do with the \'s but I cant seem to figure it out.
ogPath = folderPath.split("\");
I have also tryed two of them. Thanks for the help
- Solid0
The "\" slashes in a windows path act as escape sequences. You have 2 options here (AFAIK), depending on how your obtaining/generating your path:
1/ Just use "/" slashes instead, so "C:\Windows" becomes "C:/Windows"
2/ or if you have to use "\", then for every "\" you need to add a "\" to escape it, so:
var path = "C:\Windows\Fonts";
becomes
var path = "C:\\Windows\\Fonts";
then you can split it like this:
var a = path.split("\u005c");
where "\u005c" is the unicode equivalent of "\"
HTH
- Solid0
Damn - the server escaped my escape sequences :D
#2 should read as follows, but remove the spaces between the "\" slashes:
2/ for every "\" you need to add a "\" to escape it, so:
var path = "C:\Windows\Fonts";
becomes
var path = "C:\ \Windows\ \Fonts";
then you can split it like this:
var a = path.split("\u005c");
where "\u005c" is the unicode equivalent of "\"
- ********0
can't you just do
ogPath = folderPath.split("\\" )
- ********0
i meant to write
ogPath = folderPath.split("\ \" )
two slashes next to each other, this PVn is stripping them out....