Created
January 27, 2009 11:49
-
-
Save hipertracker/53311 to your computer and use it in GitHub Desktop.
This file contains 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
# z wątku http://www.rubyonrails.pl/forum/t112-Zamiana-pojedynczych-znakow | |
require 'iconv' | |
def pl2ascii(s) | |
ascii = "acelnoszzACELNOSZZ" | |
cep = "\271\346\352\263\361\363\234\277\237\245\306\312\243\321\323\214\257\217" | |
s = Iconv.new("cp1250", "UTF-8").iconv(s) | |
s.tr!(cep,ascii) | |
end | |
puts pl2ascii('zażółć gęślą jaźń ZAŻÓŁĆ GĘŚLĄ JAŹŃ') # => zazolc gesla jazn ZAZOLC GESLA JAZN | |
=begin | |
Do generacji stringa z kodami cep1250 użyłem Pythona: | |
pl = [oct(ord(c)) for c in unicode('ąćęłńóśżźĄĆĘŁŃÓŚŻŹ', 'utf8').encode('cp1250')] | |
print ''.join(["\\%s" % c[1:] for c in pl]) | |
# => \271\346\352\263\361\363\234\277\237\245\306\312\243\321\323\214\257\217 | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment