2
$\begingroup$

I have the following pure ASCII character list:

list ={"a", "\\:1d62", "\\:2081", "\\[Beta]", "\\:2081", " ", "+", " ", \
"a", "\\:1d62", "\\:2082", "\\[Beta]", "\\:2082", " ", "+", " ", ".", \
".", ".", " ", "+", " ", "a", "\\:2099", "\\:2081", "\\[Beta]", \
"\\:2099", " ", "=", " ", "b", "\\:1d62"}

How can I convert it to Mathematica Input Form ?

I tried: FromCharacterCode[ToString[#, "ASCII"] &/@list

But it does not work.

$\endgroup$
  • $\begingroup$ You should be converting hex to decimal first before applying FromCharacterCode[]: FromCharacterCode[16^^1d62] $\endgroup$ – J. M. is away Oct 16 '18 at 13:13
  • $\begingroup$ Or ToExpression["\\:1d62"]. $\endgroup$ – Rohit Namjoshi Oct 16 '18 at 14:33
  • $\begingroup$ Do you want the output to be symbols or strings? Should it be a or "a"? Should it be \[Beta] or "[Beta]"? I assume it should be strings, otherwise you will have a mixture of strings and symbols, since there is no expression that matches " " or "+". $\endgroup$ – Carl Woll Oct 16 '18 at 15:10
  • $\begingroup$ @CarlWoll The answer to this question is exactly what I was looking for. Do you think that one could use this to automate this question: mathematica.stackexchange.com/questions/183981/… $\endgroup$ – james Oct 16 '18 at 15:30
3
$\begingroup$

As @Rohit suggests in the comments, one possibility is to use ToExpression. However, to be safer, one might want to use Symbol instead. So:

Replace[
    list,
    a_ /; StringLength[a] > 1 :> Check[SymbolName @ Symbol[a], $Failed],
    {1}
] //InputForm

{"a", "ᵢ", "₁", "β", "₁", " ", "+", " ", "a", "ᵢ", "₂", "β", "₂", " ", "+", " ", ".", ".", ".", " ", "+", " ", "a", "ₙ", "₁", "β", "ₙ", " ", "=", " ", "b", "ᵢ"}

$\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.