1
$\begingroup$

Why am I getting the error

Syntax::sntunc: Unicode longname in the string is unterminated.

from the following?

astroSymbol[name_String] := ToString[ToExpression["\[" <> name <> "]"]] <> "" ;

Is there something I need to do to wrap the escape sequence to avoid this error?

$\endgroup$
  • 6
    $\begingroup$ You have to escape the slash: "\\[" $\endgroup$ – Leonid Shifrin Nov 14 '12 at 15:15
  • $\begingroup$ That's the answer. I'm surprised it works at all without the escape (it generates the expected string). $\endgroup$ – orome Nov 14 '12 at 15:18
  • $\begingroup$ You can write an answer to your own question, now. :) $\endgroup$ – J. M. will be back soon Nov 14 '12 at 16:07
  • $\begingroup$ Related: (7610) $\endgroup$ – Mr.Wizard Feb 8 '17 at 22:52
4
$\begingroup$

To include a backslash in a string, you need to escape it, like so:

"\\[" <> name <> "]"
$\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.