Use Character Codes to Extract Special Characters from Text
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:
testString = "When in the Courseナ of human events, it becomes necessary for one people to dissolve the political bands which have ᆴconnected them with another, and to assumeメ among the Powers of the earthᄇ the ヨseparate and equal station ムto which the Laws of ラNature and of Nature�s God entitle them, a decent respectᄡ to the opinions of mankind requires thatル they should declare the causes which impel them to the sepa";Select[ToCharacterCode@testString, # > 200&]FromCharacterCode /@ %