I'm trying to get three numbers out of a string
(parse-integer "12 3 6" :start 0 :junk-allowed t)
12 ;
2
Now this returns 2
as well, which is the number where it could be parsed.
So I can now give
(parse-integer "12 3 6" :start 2 :junk-allowed t)
3 ;
4
But how do I store the value of 2
and 4
that it returned. If I setq
it into a variable only the 12
and 3
are stored?
Please read the "theory" here.
Briefly, you can bind the multiple values with multiple-value-bind
:
(multiple-value-bind (val pos) (parse-integer "12 3 6" :start 0 :junk-allowed t)
(list val pos))
==> (12 2)
You can also setf
multiple values
:
(setf (values val pos) (parse-integer "12 3 6" :start 0 :junk-allowed t))
val ==> 12
pos ==> 2
See also VALUES Forms as Places.
PS. In your particular case, you might just do
(read-from-string (concatenate 'string
"("
"12 3 6"
")"))
and get the list (12 3 6)
.
This is not the most efficient way though (because it allocates unnecessary memory).
PPS See also:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With