6.6. Ruby Chinese coding

发布时间 : 2025-10-25 13:34:06 UTC      

Page Views: 10 views

In the previous section, we have learned how to use Ruby to output “Hello, World!”. There is no problem with English, but if you output the Chinese character “Hello, World”, you may encounter Chinese coding problems.

If no encoding is specified in the Ruby file, an error will occur during execution:

#!/usr/bin/ruby -w puts "Hello World!"; 

The output of the above program execution is as follows:

invalid multibyte char (US-ASCII) 

The above error message shows that Ruby uses ASCII coding to read the sourcecode, and there will be garbled code in Chinese. The solution is as long asyou add # -*- coding: UTF-8 -*- (written in EMAC) or #coding=utf-8 just do it.

6.6.1. Example #

#!/usr/bin/ruby -w#-*- coding: UTF-8 -*-puts"Hello World!"; 

The output is as follows:

Hello World! 

Therefore, if you include a Chinese code in the source code file during the learning process, you need to pay attention to two points:

  • 1.Must be added on the first line # -*- coding: UTF-8 -*- tell the interpreter to use utf-8 to parse the source code

    1. You must set the editor to save the file’s encoding to utf-8.

《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。