searching a string array


is there a way to search a string array for a set string?

example: I have an array of all the referenced files used in the current scene. I am looking for a specific one to change the name on.

my current idea is to get the array that file -q -r creates, then create a new string with all the array components, then tokenize that by part of the name I am looking for, then tokenize that with a variable I set in the string to seperate the array comp. with.

and then grab the last part of the new array, as that would be the path I am looking for.

is there an easier way that I am missing?



ArrayTools and StringTools on Highend3D.

the itemInStringArray function:

string $myTestArray[] = {“blue”, “green”, “red”};
//string $myTestString = “green”;
//itemInStringArray $myTestString $myTestArray;

the stringNthWord function:

stringNthWord “left_wrist_controller” 2 “_”;
// Result: wrist //

the stringRepalceNthWord function:

stringReplaceNthWord “hello world.” “mellow” 1 " ";
// Result: mellow world. //



hmmm, those are helping a bit, gonna have to read thru them a bit…I am also only searching for a protion of the whole string.


would this work?

string $thing
string $things[]

for ($thing in things)
if ($thing = sumfin) do something to $thing


Sedric, thanks, I will give that a try…and thank you too Melon :wink:



Note that you might (MIGHT, not definitely) get into trouble using the == operator on strings, because == is intended for use with numeric values. The strcmp function checks for string equality.

Anyway, you can loop over the strings in your array and use the “match” or “gmatch” commands to find substrings. “gmatch” is the easiest, because if you want something that contains “foo” you can use the search string “foo”. The match command requires that you know regular expressions.

– Mark


This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.