Atom Posted November 13, 2017 Share Posted November 13, 2017 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. index=i; 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); } Quote Link to comment Share on other sites More sharing options...
MrScienceOfficer Posted November 13, 2017 Share Posted November 13, 2017 Why not s@file = "thing/another/geom.rs"; s@file = concat(join(split(s@file, '.')[:-1],''), ".bgeo.sc"); ? Quote Link to comment Share on other sites More sharing options...
Atom Posted November 14, 2017 Author Share Posted November 14, 2017 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. Quote Link to comment Share on other sites More sharing options...
MrScienceOfficer Posted November 14, 2017 Share Posted November 14, 2017 s@file = "thing/another/geom.001.rs"; s@file = concat(join(split(s@file, '.')[:-1],'.'), ".bgeo.sc"); note the added dot joining the split. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.