比如\u770B\u89C1 怎么将他变成汉字输出啊 在网上查的 Iconv.conv("utf-8","utf-16",str) 这个方法貌似不行啊
完整代码是
#encoding: utf-8
english_map=[]
china_map=[]
index=0
puts "系统初始化中,请等待......"
File.open("text.txt","r:utf-8").each do |i|
english_map[index] = i.to_s.scan(/([a-zA-Z]+)=/)
china_map[index] =i.to_s.scan(/=([\u4E00-\u9FA5]+)/)
index+=1
end
def run_topic(result, num, english_map, china_map)
if result==china_map[num]
puts "正确!"
puts "任意键继续。"
temp=gets
else
puts "不正确!"
puts "输入1查看正确意思,输入2再次作答,输入其他换一题。"
temp=gets
if temp.to_i == 1
puts "正确答案为:#{china_map[num]}"
elsif temp.to_i == 2
run_topic(input_result(num, english_map), num, english_map, china_map)
end
end
end
def input_result(num, english_map)
puts "请输入 #{english_map[num]} 汉语意思:"
return result=gets
end
puts "初始化完毕。"
while true
num = rand(english_map.length-1)
result = input_result(num, english_map)
run_topic(result, num, english_map, china_map)
end
text.txt内容为:
feel=感觉
fill=填充
leap=跳
lip=嘴唇
...
等等