iamjaideep80 Posted February 14, 2006 Share Posted February 14, 2006 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 Quote Link to comment Share on other sites More sharing options...
Mario Marengo Posted February 14, 2006 Share Posted February 14, 2006 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. Quote Link to comment Share on other sites More sharing options...
iamjaideep80 Posted February 14, 2006 Author Share Posted February 14, 2006 Thank u Mario...... It works!!!!!! Thank u very much. I knew abt printf(), but not abt sprintf(). ------ iamjaideep80 Quote Link to comment Share on other sites More sharing options...
sibarrick Posted February 14, 2006 Share Posted February 14, 2006 There is also concat in vex from the vex help string concat(string s1, s2, ...) Concatenate all the strings specified to form a single string. This is equivalent (but slightly more efficient when there are more than 2 strings) to adding all the strings together. Quote Link to comment Share on other sites More sharing options...
Mario Marengo Posted February 14, 2006 Share Posted February 14, 2006 There is also concat in vex 24698[/snapback] Yup; use concat() when all your arguments are strings, and use sprintf() when concatenating arguments of different type (string+int+vector+matrix+etc.). Quote Link to comment Share on other sites More sharing options...
sibarrick Posted February 14, 2006 Share Posted February 14, 2006 Oh yeah sorry forgot you were specifically asking about strings and int. oops. Quote Link to comment Share on other sites More sharing options...
iamjaideep80 Posted February 15, 2006 Author Share Posted February 15, 2006 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 Quote Link to comment Share on other sites More sharing options...
Mario Marengo Posted February 15, 2006 Share Posted February 15, 2006 See my response in the SESI forum. 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.