3
$\begingroup$

I have a list of numbers separated by semicolon in text file and I would like to import the data and work with them. If I use

data = ReadList["file",Word,WordSeparators -> ";"] /. Word -> Number

it gives me word or string instead of number. What can I do?

$\endgroup$
  • $\begingroup$ ToExpression@ ReadList["file",Word,WordSeparators -> ";"] ? $\endgroup$ – kglr Jun 1 '17 at 21:26
  • 3
    $\begingroup$ or ReadList["file", "Number", "RecordSeparators" -> {";"}]? $\endgroup$ – kglr Jun 1 '17 at 21:30
  • $\begingroup$ ImportString[ StringReplace[Import[ file , "Text"] , ";" -> ","] , "CSV"] maybe. (also caution ToExpression wont work if any of the numbers are in E exponent form ) $\endgroup$ – george2079 Jun 1 '17 at 22:08
3
$\begingroup$
file = StringToStream["1;2;3;4.5;5.5;6.5"];
ReadList[file, Number, RecordSeparators -> {";"}]

{1, 2, 3, 4.5, 5.5, 6.5}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.