Hello.
I'm trying to convert a string into an integer in hoc code. I haven't found anything particularly useful in the built-in functions (is there really anything?) and I have been trying to use external functions, such as the atoi c function or the java.lang.Integer java class. But I think that I'm missing something in the way that I'm using these.
I will greatly appreciate any help.
Thanks
string 2 integer
-
- Posts: 9
- Joined: Mon May 29, 2006 12:33 pm
- Location: National Technical University of Athens
Sscanf is the function you are looking for. See the example below (taken from the quick reference) which reads integers given in hex, binary and decimal format. Full documentation can be found in the quick reference: http://www.neuron.yale.edu/neuron/stati ... tml#sscanf.
This question however belongs I think in the "Getting Started" or "Other Questions" forum.
Code: Select all
strdef s
double x[20]
sscanf("this is a test\n", "%*s%s", s)
sscanf("0xff 010 25", "%i%i%i", &x[0], &x[1], &x[2])
print x[0], x[1], x[2]
-
- Posts: 9
- Joined: Mon May 29, 2006 12:33 pm
- Location: National Technical University of Athens