文字コードを使ってテキストから特殊文字を抽出する
インポートするテキストに特殊文字が含まれていて,それを削除したいという場合がある.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 /@ %