Hello, I have got here the @neighbours that contains the neighbour primitives for each primitive. It happens to be a string.
I need an integer array with the neighbour primitives.
So, how can I convert a string “1 2 3 4 5 3 4 7” (whatever it is) into an integer array?
As you can see I could already split it into different characteres but need some help to finish it.
Thanks in advance.
Convert a string array into an integer array
4295 4 2- Dav_Rod
- Member
- 40 posts
- Joined: March 2018
- Offline
- BabaJ
- Member
- 2036 posts
- Joined: Sept. 2015
- Offline
- Dav_Rod
- Member
- 40 posts
- Joined: March 2018
- Offline
Thanks Babaj for the fast answer. I get the idea. I tried that but could not reach a good result, maybe because of some syntax error that I can not clean.
I also tried this:
I attach the file in the case it can help.
Thanks in advance.
I also tried this:
if(@balcon == 1){ string vecinos = primattrib(0, "neighbours", @primnum, 1); string letras[] = split(vecinos); int numbers[]; foreach(string asdfg; letras) { push(numbers, atoi(asdfg)); } }
I attach the file in the case it can help.
Thanks in advance.
- BabaJ
- Member
- 2036 posts
- Joined: Sept. 2015
- Offline
I noticed your printf line.
Is that where your having issues?
Your running over primitives yet only creating an array of two ints for only when @balcon == 1.
But your still running over all the prims with the printf command, so when it tries to print for the prims with @balcon == 0,
it doesn't see an array, because you didn't create one for those prims.
If your ‘numbers’ array variable was an attribute, then a numbers attribute array would have been created for all prims, but since you still will only have values for that array on prims that are @balcon == 1, the other prims with that array would be empty and you still would get an error with your print command as is.
Have to remember that when ‘running over’ with wrangles it's multi-threading, so sometimes you need to do a second wrangle that follows if what your trying to accomplish can't be done in the one wrangle - or as a last option, run in detail mode.
I've changed your wrangle node and made the numbers variable into an attribute, so you can see that the values indeed get stored. And another wrangle that follows with the print command, just as another way so you can see.
Is that where your having issues?
Your running over primitives yet only creating an array of two ints for only when @balcon == 1.
But your still running over all the prims with the printf command, so when it tries to print for the prims with @balcon == 0,
it doesn't see an array, because you didn't create one for those prims.
If your ‘numbers’ array variable was an attribute, then a numbers attribute array would have been created for all prims, but since you still will only have values for that array on prims that are @balcon == 1, the other prims with that array would be empty and you still would get an error with your print command as is.
Have to remember that when ‘running over’ with wrangles it's multi-threading, so sometimes you need to do a second wrangle that follows if what your trying to accomplish can't be done in the one wrangle - or as a last option, run in detail mode.
I've changed your wrangle node and made the numbers variable into an attribute, so you can see that the values indeed get stored. And another wrangle that follows with the print command, just as another way so you can see.
- Dav_Rod
- Member
- 40 posts
- Joined: March 2018
- Offline
-
- Quick Links