I think you’ve solved it. I was confused by thinking printing a string would show the quotes around it. Many thanks!
That still leaves me with a question I asked previously: how can I get [1,2,3] from “[1,2,3]”?
It seems I can print [1,2,3], but how can I assign it to a variable?
Conversely, is there a way to read a line of input from the console other than as a string?
You can also evaluate arbitrary expressions from strings in the global scope, with e.g.:
include_string(Main, "[1,2,3]")
or
eval(Meta.parse(["1,2,3"]))
But it is not the recommended way to go. For instance, this cannot be done locally inside a function. @mzaffalon’s proposal is better, although not applicable to arbitrary strings.
Your suggestion: parse.(Int, split(strip(str, ['[', ']']), ',’))
works, but the resulting vector has spaces between each element, eg, [1, 2, 3].
To save space, I’d prefer [1,2,3]. How do I modify the parse expression to avoid the spaces?
What do you mean by “the vector has spaces”? Whether or not there are spaces is just a printing/display issue, the underlying vectors are the same irrespective of the whitespace between elements:
But again this is just a display issue, there are no “spaces” in the actual object [1, 2, 3], which is just a Vector{Int64}, which by default gets displayed in the way you show when not displayed on its own: