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$
4
  • 6
    $\begingroup$ You have to escape the slash: "\\[" $\endgroup$ Nov 14, 2012 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, 2012 at 15:18
  • $\begingroup$ You can write an answer to your own question, now. :) $\endgroup$ Nov 14, 2012 at 16:07
  • $\begingroup$ Related: (7610) $\endgroup$
    – Mr.Wizard
    Feb 8, 2017 at 22:52

1 Answer 1

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 and acknowledge you have read our privacy policy.

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