VEX: re_replace frontslash for backslash?

   1597   6   1
User Avatar
Member
1004 posts
Joined: April 2017
Offline
HI!

I've got a point s@instancepath that has many different paths with frontslashes and I need them to be backslashes so it works in Windows.

I tried using this script:

s@instancepath = re_replace("/", "\", @instancepath);

But the backslash is causing a problem in the script. Everything after the backslash turns green, indicating that everything after it is considered a string.

Any way to bypass that probleme?

-Olivier
Edited by olivierth - June 23, 2022 10:30:10
User Avatar
Member
1004 posts
Joined: April 2017
Offline
AHHHHAAA!!! Found the solution!

By using a channel, it bypasses that vex problem.

Attachments:
backslash_solution.JPG (30.8 KB)

User Avatar
Member
7741 posts
Joined: Sept. 2011
Offline
just put \\
User Avatar
Member
1004 posts
Joined: April 2017
Offline
What does a double backslash do? Wouldn't that give me : "blah\\blahblah\\etc." ?
User Avatar
Member
42 posts
Joined: March 2019
Offline
olivierth
What does a double backslash do? Wouldn't that give me : "blah\\blahblah\\etc." ?


As I understand it the "\" is a special character that is used to access more functionalities. So if you use a "\" in front of another character it changes the meaning of that character. For example, "\n" would be a line jump. And if use "\\" it is still a backslash with a special meaning. Therefore you have to at least use three backslashes to represent a correct/normal backslash.
So in your case, you'd have to put it like this to make it work within the function.

s@instancepath = re_replace("/", "\\\", @instancepath);

Feel free to correct me if I was talking shit

Greetings
User Avatar
Member
7741 posts
Joined: Sept. 2011
Offline
Lucca
olivierth
What does a double backslash do? Wouldn't that give me : "blah\\blahblah\\etc." ?


As I understand it the "\" is a special character that is used to access more functionalities. So if you use a "\" in front of another character it changes the meaning of that character. For example, "\n" would be a line jump. And if use "\\" it is still a backslash with a special meaning. Therefore you have to at least use three backslashes to represent a correct/normal backslash.
So in your case, you'd have to put it like this to make it work within the function.

s@instancepath = re_replace("/", "\\\", @instancepath);

Feel free to correct me if I was talking shit

Greetings

The backslash is an escape character. It generally removes the special function of the following character. For example, a dollar sign or @ symbol may have a meaning in the interpreter. Another character with meaning is the quote symbol for defining strings. The backslash makes the quote symbol into a regular character instead of a string delimiter. This also applies to the backslash as an escape character. Since that is also a special meaning. The backslash escapes the escape character for a literal backslash. Sometimes there are multiple levels of string parsing going on such as with vex expressions. In this case there are multiple opportunities for the escape character to be consumed. This is why you might see three or four slashes in a row. Fun fact, there used to be a bug with backslashes in parameter expressions as part of otl definitions. This caused the number of slashes to double each time the otl was edited causing Houdini scenes to balloon in size. At one point I saw simple scene files take up a gig or more!
User Avatar
Member
1004 posts
Joined: April 2017
Offline
Very interesting! Thanks for the info from both of you!

As we say in french, "I'll go to bed a bit less stupid"

-Olivier
  • Quick Links