“无效多字节字符(US-ASCII)” ä,ü,ö,ß的错误是Ascii! [英] "Invalid multibyte char (US-ASCII)" error for ä, ü, ö, ß which are Ascii!

查看:167
本文介绍了“无效多字节字符(US-ASCII)” ä,ü,ö,ß的错误是Ascii!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要处理一些国际字符,即ä,ü,ö和ß,它们仍然是ascii。

My application needs to handle some international characters, namely ä, ü, ö and ß, which are still ascii.

当我在交易时测试了ruby的行为与这些字符,我有这个错误:

When I tested the behavior of ruby when dealing with these chars, I got this error:

test.rb:1: invalid multibyte char (US-ASCII)
test.rb:1: invalid multibyte char (US-ASCII)

p>

for this code:

puts "i like my chars: ä, ü, ö and ß!"

但奇怪的是:当使用Interactive Ruby Shell时,我没有错误!

But the strange thing is: When using the Interactive Ruby Shell, I get no error!

编辑:在我的应用程序中,我从外部api检索数据。上面的代码只是一个例子!

推荐答案

放置魔术评论#coding: utf-8 在开始你的脚本(在第二行,如果你使用shebang)。

Put the magic comment # coding: utf-8 at the beginning your your script (on the second line if you're using shebang).

#!/usr/local/bin/ruby
# coding: utf-8

puts "i like my chars: ä, ü, ö and ß!"

这篇关于“无效多字节字符(US-ASCII)” ä,ü,ö,ß的错误是Ascii!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆