使用字符代码提取文本中的特殊字符
当你导入文本时,有时,你想去掉它所包含特殊字符. 函数 ToCharacterCode 和 FromCharacterCode 可用于从文本块中提取出特殊的字符.
这串文字来自于独立宣言,包含各种特殊字符. 因为这些特殊字符的字符代码比文本中的其他字符大很多,你可以使用 Select 提取,然后使用 FromCharacterCode 根据原始字符代码重新构建:
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 /@ %