Saying we have a string:
"1 2 3 4 5 6"
I want to convert this to integer list. First I do:
In[82]:= str = StringReplace["1 2 3 4 5 6", " " -> ","] // List
Out[82]= {"1,2,3,4,5,6"}
No I need to convert Out[82]
to be just {1,2,3,4,5,6}
.
Any idea? Thanks!
Answer
res = ToExpression@StringSplit["1 2 3 4 5 6", " "]
{1, 2, 3, 4, 5, 6}
Head /@ res
{Integer, Integer, Integer, Integer, Integer, Integer}
Comments
Post a Comment