6.6. Ruby Chinese coding

发布时间 :2023-10-24 23:00:07 UTC      

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.

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.