How to replace a space by a comma
expression = "{1 2 3 4 5 6 7 8}";
A few alternatives to PlatoManiac's approach:
ToExpression[
expression,
StandardForm,
Function[e, Sequence @@@ Unevaluated[e], HoldAll]
]
or
ToExpression @ StringReplace[expression, " " -> ","]
{1, 2, 3, 4, 5, 6, 7, 8}
or
StringCases[expression, n : NumberString :> ToExpression[n]]
ToExpression @ StringCases[expression, NumberString]
A possibility with WhitespaceCharacter
ToExpression@
StringReplace[expression, WhitespaceCharacter -> ","]
(* {1, 2, 3, 4, 5, 6, 7, 8} *)
Another using Interpreter
Interpreter[
DelimitedSequence["Integer", {"{", " ", "}"}]][expression]
My thought was to drop the brackets using StringTake
and then import it using ImportString
"{1 2 3 4 5 6 7 8}"~StringTake~{2, -2}~ImportString~"Table" // First
(* {1, 2, 3, 4, 5, 6, 7, 8} *)
edit I just realized this is very similar to what J.M. suggested in his comment (although I'm playing around with infix notation here).