PDA

View Full Version : returning all the elements of an array string into a string


Vitoratti
05-12-2006, 01:12 PM
Hi guys!

How do I return all the elements of a string array, separate for a space into another string variable ?

I found in the documentation the command stringArrayToString, but for some reason it is not working.
Maybe I am doing something wrong… don’t know.:sad:

Just an example:


{
string $objsSel[] = `ls -sl` ;
string $newStr = `stringArrayToString($objsSel, " ")`;
}



Thanks for your attention!

[ ]s

Mikademius
05-12-2006, 01:53 PM
I tried to tokenize this with " ", but that doesn't work.
I figured you could use this rather clumsy sollution:

string $selected[] = `ls -sl`;
string $newString[];
int $loop;

for ($loop = 0; $loop <= (`size($selected)`); $loop++ ){
$newString[$loop] = $selected[$loop];
}

print $newString;


There must be an easier way...

And more importantly; change your typing color man so we don't have to hilite it to see what you write ;)

Vitoratti
05-12-2006, 02:31 PM
Hey Mikademius!
Thank you for the answer and excuse me for the black color of the text, I didn't notice. I already modified! hehe
The problem with that solution, it is the fact of giving me another array, and the problem is that I have several arrays that need to be composed in a single string variable (I am planning to use the commando fprint to write this information).



[ ]’s

Mikademius
05-12-2006, 02:47 PM
Maybe this is a way to do it?


string $values1[] = {"red" , "green" , "blue"};
string $values2[] = {"black" , "white" , "grey"};

appendStringArray($values1, $values2, `size($values2)`);

string $gateherValues[] = $values1;
clear $values1;

print $gateherValues;


This actually adds the values from the first string to the other. It doesn't concatenate them... But it could be used as an alternative.

RonGriswold
05-12-2006, 02:56 PM
It appears that the major problem is that stringArrayToString is a MEL function and not an API command. As such the ``'s around it are not necessary and in fact will cause errors. When I removed these, your code worked just fine.

Ron

Mikademius
05-13-2006, 07:21 AM
haha,now would you look at that :)

Vitoratti
05-13-2006, 04:24 PM
:p Thanks ! :) :thumbsup:

CGTalk Moderation
05-13-2006, 04:24 PM
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.