I have a set of data read in from a larger CSV file. I want it to match the format I have from another analysis. It is structured as a series of strings with letters and numbers Here it is copy-pasted from Mathematica
{"{H, 1}", "{H, 2}", "{H, 3}", "{Mg, 1}", "{Mg, 1}", "{Mg, 1}", "{C, \
1}", "{C, 1, H, 1}", "{N, 1}", "{N, 1, H, 1}"}
I want to convert it to:
{{"H", "1"}, {"H", "2"}, {"H", "3"}, {"Mg", "1"}, {"Mg", "1"}, {"Mg",
"1"}, {"N", "1"}, {"N", "1", "H", "1"}}
I've tried Read
and StringToStream
but I haven't been able to do what I need.
I've also solved it. I wasn't on the right track, once I looked at the simple string manipulation tools after posting the question the solution jumped out at me.
data = Map[StringTrim[#, ("{" | "}") ...] &, data];
data = Map[StringSplit[#, ","] &, data]
data = StringTrim/@data