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: