logix1390 Posted July 15, 2019 Share Posted July 15, 2019 Hello. I am trying to get the integer value from my rbd piece names "piece0", piece1", piece3", etc . and convert that into a string I am trying to do this based on what the help card has said: int atoi(string str) i@nameInt= atoi(s@name); Am I not doing this correctly? this will return 0 Any help would be appreciated. thank you. atoi_int_to_string.hipnc Quote Link to comment Share on other sites More sharing options...
Atom Posted July 15, 2019 Share Posted July 15, 2019 (edited) You have to parse the string, of course. Fortunately, your piece name all have the same length prefix, so you can get away with an array manipulation, using a constant. i@nameInt= atoi(s@name[5:]); https://www.sidefx.com/docs/houdini/vex/strings.html Edited July 15, 2019 by Atom Quote Link to comment Share on other sites More sharing options...
logix1390 Posted July 15, 2019 Author Share Posted July 15, 2019 @Atom Thank you for the response Atom. That makes sense now. I can't help but ask a few follow up questions. So as you mentioned, my name attribute in this case has the same length prefix which is making it easy to isolate the integer for the atoi function. So if I had a different name attribute with a longer length prefix then it will return 0 if I were to use the same expression . My question is , how would I automatically detect the length of the name prefix to always isolate the integer at the end ? My first thought would be to find the length of the string using the len function.. i@mylen=len(@name); i@nameInt= atoi(s@name[@mylen:]); But this of course wont work because that will find the length of the string including the integers. Is there anything else I should be looking into to achieve this ? Thank you Quote Link to comment Share on other sites More sharing options...
Skybar Posted July 15, 2019 Share Posted July 15, 2019 i@test = opdigits(s@name); https://www.sidefx.com/docs/houdini/vex/functions/opdigits.html 3 Quote Link to comment Share on other sites More sharing options...
logix1390 Posted July 16, 2019 Author Share Posted July 16, 2019 @Skybarthank you! 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.