I have a number of .csv files that have a semicolon (;) delimiter rather than comma, and I'm wondering if there is a simple way to change the text in them all.
Lets say I have a test file "a.csv" with text:
1;0.5;7
2;0.4;8
3;0.6;7
And I want to convert the semicolons to commas, such that it can import nicely as a csv file.
Test = "1;0.5;7
2;0.4;8
3;0.6;7"
Export["a.csv", Test](*Creates Test File*)
Export["a.csv", ToExpression[
StringReplace[Import["a.csv", "String"],
{";" -> ",", "\r\n" -> "\n"}]]](*Imports/Replaces/Exports*)
FullForm@Import["a.csv", "CSV"](*Read Output*)
Running the above code results in:
List[List["1,0.5,7\n2,0.4,8\n3,0.6,7"]]
Which is wrong and I'm looking for something that would make:
List[List[1,0.5`,7],List[2,0.4`,8],List[3,0.6`,7]]
The above code works if I am dealing with .txt files, but doesn't seem to function with .csv files. However, I hope to keep the .csv tag in the file names. Is there something I'm missing, or some simpler method?
"Table"
format instead?ImportString["1;0.5;7 2;0.4;8 3;0.6;7", "Table", "FieldSeparators" -> ";"]
$\endgroup$Export["a.csv", ToExpression[ StringReplace[ Import["a.csv", "String"], {";" -> ",", "\r\n" -> "\n"}]], "String"]
$\endgroup$