简体   繁体   English

无效的多字节字符(UTF-8)

[英]Invalid multibyte char(UTF-8)

I am trying compile this Ruby code with option --1.9 : 我正在尝试使用选项--1.9编译此Ruby代码:

\# encoding: utf-8                        
module Modd               
  def cpd          
    #"_¦+?" mySQL         
    "ñ,B˜"        
  end    
end   

I used the GVim editor and compiled then got the following error: 我使用了GVim编辑器并进行了编译,然后出现以下错误:

SyntaxError: f3.rb:6: invalid multibyte char (UTF-8)

After that I used Notepad++ and changed to Encode as UTF-8 and compiled with this option: 之后,我使用Notepad ++并将其更改Encode as UTF-8并使用以下选项进行编译:

jruby --1.9 f3.rb

then I get: 然后我得到:

SyntaxError: f3.rb:1: \273Invalid char `\273' ('╗') in expression

I have seen this happen when the BOM gets messed up during a charset conversion (the BOM in octal is 357 273 277 ). 我已经看到在字符集转换过程中BOM混乱时发生了这种情况(八进制的BOM是357 273 277 )。 If you open the file with a hexadecimal editor ( :%!xxd on vi ), you will more than likely see characters at the beginning of the file, before the first # . 如果使用十六进制编辑器( vi上的:%!xxd )打开文件,则很有可能在文件开头,第一个#之前看到字符。

If you recreate that file directly in utf-8, or get rid of these spurious characters, this should solve your problem. 如果直接在utf-8中重新创建该文件,或者摆脱了这些虚假字符,这应该可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM