Jump to content

Concat String And Int In Vex


Recommended Posts

Hi Everybody........

The solution to the problem I am having can be very simple, but not being able to solve it.

How to Concat a string and an integer variable say "i" in VEX.

I wanted to create a SOP creating number of groups given by user.

i tried different things like,

newgroup("group"i);

newgroup("group"&i);

newgroup("group"+i);

newgroup("group"$i);

But nothing is working. Plz Help.

Thanking in advance.

-----iamjaideep80

Link to comment
Share on other sites

The solution to the problem I am having can be very simple, but not being able to solve it.

How to Concat a string and an integer variable say "i" in VEX.

24682[/snapback]

Hi there,

I believe what you're looking for is the function sprintf().

Similar to printf() in that it takes a format string and a varying number of value parameters that get substituted into the format string, except that sprintf() "prints" into a string instead of a file stream. See the help card for the available format characters.

In your example, you could use it like this:

int i;
for(i = 0; i < 10; i++) {
   newgroup(sprintf("group%d",i));
}

which would create the groups

group0, group1, group2, group3, ... , group9

Hope that helps.

Cheers.

Link to comment
Share on other sites

Thank u very much, all of u.

I got it, and its working.

But there came another problem.

As far as my knowledge, In case of SOP, Houdini executes all of the Vex program for all the points, one point at a time, And with "ptnum" variable we can get current point being processed. Right? Then why following code is not working.

Don't ask me the use, but i want to write a code that will take all the points, and will put them in different groups, with one point in each group. And the code is.....

sop Test03()

{

string this_grp = sprintf("group%d",ptnum);

newgroup(this_grp);

addgroup(this_grp,ptnum);

}

So suppose i have a grid with 100 points , from point number 0 to 99, it should give me 100 groups with corresoponding points in it. But when I did it, only one group "group0" is created and all the 100 points are added to it. Why??????????

When I tried to play with the logic, and wrote something like this......

sop Test03()

{

int i = 0;

for(i = 1;i<=Npt;i=i+1)

{

string this_grp = sprintf("group%d",i);

newgroup(this_grp);

if(ptnum==i)

{

addgroup(this_grp,ptnum);

}

}

}

This one is working fine, but is too expensive,

Why the First one is not working, when it is logically correct?????????????/

Waiting for your answer.

--------iamjaideep80

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...