http://www.ruby-forum.com/topic/182957

 

arr = []
arr << dec_num
str = arr.pack("U") #U=UTF-8 => encode unicode 8364 into a UTF-8
character.
puts str
 
php
http://stackoverflow.com/questions/3704538/php-construct-a-unicode-string 

 

#!/usr/bin/env ruby
#unicode decimal value to string
def decToStr(dec_num)
  arr = []
  arr << dec_num
  str = arr.pack("U")
  return str
end
fread = File.new("./uao.csv","r")
while (line=fread.gets)
  dec_num=line.split(',')[1].to_i(16) if (!line.split(',')[1].nil?)
  puts decToStr(dec_num)
end

fread.close

 

#將md5加密的字利用uao列表比對還原,未優化

#!/usr/bin/env ruby
require 'iconv'
require 'digest/md5'

uao = Array.new
fread = File.new("./uaowords.big5","r")
while (line=fread.gets)
  str=line.chomp
  md5value=Digest::MD5.hexdigest("#{str}")
  #printf("%s,%s\n",str,md5value)
  uao << sprintf("%s,%s",str,md5value)
end
fread.close

dbCsv=Array.new
fread = File.new("./db.csv.big5","r")
while (line=fread.gets)
  dbmd5=line.chomp.split(',')[1].gsub('\'','')
  pinyin=line.chomp.split(',')[2..-1].join(',')
  uao.each do |x|
    uaoword=x.chomp.split(',')[0]
    uaomd5=x.chomp.split(',')[1]
    if(dbmd5==uaomd5)
    printf("%s,\'%s\',%s\n",line.chomp.split(',')[0],uaoword,pinyin)
    end
  end
end
fread.close

創作者介紹
創作者 igogo 的頭像
igogo

牛大叔.生活隨筆

igogo 發表在 痞客邦 留言(0) 人氣()