Skip to main content

string manipulation - 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?



Answer



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


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

Comments