Created
February 9, 2018 14:18
-
-
Save trytone/3e8f53341b741da0f44ec4606661a2b0 to your computer and use it in GitHub Desktop.
Perl - Remove polish characters from UTF-8 string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use utf8; | |
| use Encode qw(decode encode); | |
| # Source code should be saved in UTF-8 encoding | |
| my $sting = 'ąćźłóżęĄĆŹŁÓŻĘ'; | |
| my $nonUTF = encode("UTF-8", $sting); | |
| my $filters = { | |
| "\xC4\x85" => 'a', # ą | |
| "\xC4\x87" => 'c', # ć | |
| "\xC4\x99" => 'e', # ę | |
| "\xC5\x82" => 'l', # ł | |
| "\xC5\x84" => 'n', # ń | |
| "\xC3\xB3" => 'o', # ó | |
| "\xC5\x9B" => 's', # ś | |
| "\xC5\xBA" => 'z', # ź | |
| "\xC5\xBC" => 'z', # ż | |
| "\xC4\x84" => 'A', # Ą | |
| "\xC4\x86" => 'C', # Ć | |
| "\xC4\x98" => 'E', # Ę | |
| "\xC5\x81" => 'L', # Ł | |
| "\xC5\x83" => 'N', # Ń | |
| "\xC3\x93" => 'O', # Ó | |
| "\xC5\x9A" => 'S', # Ś | |
| "\xC5\xB9" => 'Z', # Ź | |
| "\xC5\xBB" => 'Z', # Ż | |
| }; | |
| foreach $from (keys %{$filters}){ | |
| my $to = $filters->{$from}; | |
| $nonUTF =~ s/$from/$to/; | |
| } | |
| print $nonUTF; # aczlozeACZLOZE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment