# How do I construct a “named character” programmatically?

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?

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

## 1 Answer

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

"\\[" <> name <> "]"