Showing posts with label ie. Show all posts
Showing posts with label ie. Show all posts

Monday, September 28, 2009

SJIS and UTF8

Stuck in chr encoding!


Encode Situation.
target site : UTF-8
test data : SJIS(CP932)


source file encode:sjis


#! ruby -ks
~some code~
WIN32OLE.codepage = WIN32OLE::CP_UTF8 # -> for target site encode
# string for ie
some_str = 'SJIS str 日本語です。'
give_str = some_str.toutf8


blogger sanitized my code that's why 2byte chr.
なぜ、こんなことになってしまったか?
読み込むCSVがCP932で書かれていて、これは変更できない制限がある。
テストするサイトはUTF8のエンコーディングで、これも変更できない制限がある。
で、CSVのデータを読み込むときに-kuだと、化ける。
-ksで読み込んで、toutf8でエンコードして、WIN32OLE::CP_UTF8で、
ieインスタンスからutf8でもらって$KCODE=UTF8でregexpすることに
必要だった。
他に良い、方法あるのか模索中