Jump to content
Sign in to follow this  

VEX Based Replace File Extension

Recommended Posts

VEX is missing some basic strings features that other languages have.

Here is a way to replace the file extension on a VEX string.

// Replace Redshift .rs file extension with companion .bgeo.sc in the same folder.
// Feed this node to Display only output.
int index = -1;
string left_part = "";
int l = len(s@instancefile);
for (int i=l; i>0; i--) {
    string char = s@instancefile[i];
    if (char == ".") {
        // Found first occurence of . while scanning backwards through string.
        i=0;        // break loop.
if (index != -1) {
    // We have a split point.
    left_part = s@instancefile[:index];
    // Attach alternate file extension for viewport instancing to work.
    s@instancefile = sprintf("%s.bgeo.sc",left_part);



Share this post

Link to post
Share on other sites

That can work too but it assumes there is only one period/dot in the provided filename which might not always be the case.

Your posted code can fail on a name like this...

s@file = "thing/another/geom.001.rs";
s@file = concat(join(split(s@file, '.')[:-1],''), ".bgeo.sc");

By scanning backwards through the string I can always be sure the first period I encounter is the correct split point.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this