concatenate a string with a component


#1

Hello there, I’m not sure how to concatenate this line,
$vert = $list[0]+".vtx["+“5]” ;

I got this message.

$list = ls -sl;
// Result: pCube1 //
$vert = $list[0]+".vtx["+“5]” ;
// Error: $vert = $list[0]+".vtx["+“5]” ; //
// Error: Line 1.31: Cannot cast data of type string to string[]. //

Thanks in advance.


#2

I suppose you somehow assigned an string array to $vert.
Try to declare $vert correctly as string:

string $vert = $list[0]+".vtx["+"5]" ;

#3

Thanks Haggi, still not working, but actually if I try this line a got a syntax error,

select -r $list[0]+".vtx[" + “5]”;

and I even try this way.

string $vert = $list[0]+".vtx["+ 5 +"]" ;

I believe I’m doing something wrong, just can’t figure out.

thanks again.


#4

This works fine for me:

string $list[] = `ls -sl`;
string $vert = $list[0]+".vtx["+"5]";
select $vert;


#5

Just confirming that haggi’s code works here too.

The way you have broken that line looks redundant to me though. Why not just “.vtx[5]” ? Unless you eventually need to specify the index as a variable, in which case this works…

{
string $list[] = `ls -sl`;
int $idx = 4;
string $vert = ($list[0]+".vtx["+ $idx +"]");
select $vert;
}

Those extra brackets are not a requirement in this case, but in other examples they would be, so I find myself always doing it just to be sure.

David


#6

cool, haggi I didn’t declare the list like

string $list[] = ls -sl;

I did it without the string, maybe thats why didn’t work for me before… but now is working.

thanks a lot for both of you.

All the best.

hto