Use Character Codes to Extract Special Characters from Text

Sometimes when you import text, it will contain special characters that you want to get rid of. The functions ToCharacterCode and FromCharacterCode can be used to get special characters out of a block of text.

    
This string of text, from the Declaration of Independence, contains a variety of special characters. Since the character codes for these special characters are much larger than those of the other characters in the text, you can use Select to extract them and then use FromCharacterCode to reconstruct them from their raw character codes:
In[24]:=
Click for copyable input
In[25]:=
Click for copyable input
Out[25]=
In[26]:=
Click for copyable input
Out[26]=
New to Mathematica? Find your learning path »
Have a question? Ask support »