[Closed] Remove escape sequence from file path string
Already searched in this forum and didn´t found any asnwer to this question: Anybody knows how to filter a string to add double backslashes to a path when it has a escape sequence, i.e. ” “, “
“?
I´m trying to correct some paths by script and got this problem. tried to create a function which would filter this, through a array of sequences, but the string is already wrong when it´s read by the function.
sorry my bad english, hope the question is clear…
Gustavo
heres a clip o code that i’ve been using for so long that i dont really remember where it came from, so sorry to the origonal guy, i’m sure its obvious by the functionname to whoever did it lol >:)
fn makeHappyFileName str =
(
c = str.count
local newstr = ""
for i = 1 to c do
(
if str[ i ] == "\\" then newstr += "\\\\"
else newstr += str[ i ]
)
return ("\"" + newstr + "\"")
)
Here’s another function. It’s a bit more flexible in the way it lets you specify the tokens to be replaced and the character/string which will replace those tokens.
fn filterStr str tokens replacement = (
local finalStr = ""
local splits = filterString str tokens
for i = 1 to splits.count - 1 do (
finalStr += splits[i] + replacement
)
finalStr += splits[splits.count]
)
So if you have a string like this one (weird, I know!):
"C:\"3dsmax8\scenes Hola
"
And you want to replace the characters ‘”’, ‘’, ’ ’ and ’
’ for double backslashes, you’ll do:
filterStr "C:\"3dsmax8\scenes Hola
" "\\
\"" "\\\\"
That will return:
"C:\\3dsmax8\\scenes\\Hola"
By the way, as you can see, it doesn’t replace the last character (if it’s an invalid token) for the replacement character/string, just deletes it. You can modify it if you don’t want this behaviour to happen.
HTH.
Thank you jonathan and vsai, but i had some problems with your functions:
filterstr "\\argo-2\maps
ew roco\xref" "
" "\\"
"\argo-2\maps\ew\roco"
with filterstring() i got the secondline showed above. it seems that the script removes the escape sequence from the string. or i couldn´t use it the right way.
makehappyfilename "\\argo-2\maps
ew roco\xref"
""\\argo-2\\maps
ew roco""
with the makehappyfilename() the results were even worst. like you can see above. seems to me the problem is that the string is read by the function already truncated by the escape sequences.
anyway, a few minutes ago i found a script in scripspot, for max 3 (believe it or not), by Swami Lama, which worked perfectly for me
but thank you again for your quick reply and help.
Gustavo