Ruby / VS Code / garbled characters

Asked 2 years ago, Updated 2 years ago, 148 views

Ruby will be garbled if you use VS Code and output the following code.

code:

address={name: "Takahashi", furigana: "Takahashi", postal: "1234567"}

Output:

{:name=>"\u9AD8\u6A4B",:furigana=>"\u30BF\u30AB\u30CF\u30B7",:postal=>"1234567"}

How can I solve this problem?

ruby garbled-characters

2022-09-29 21:47

1 Answers

It's not garbled, it's escaped because the encoding of the string literal and the external encoding do not match.

You are probably using p, but p is basically a debugging method, and if the encoding does not match, it behaves like this.

There is a way to adjust the external encoding to UTF-8.

However, in Japanese Windows environments, the external encoding is generally Windows-31J, so existing scripts that are written on that premise may malfunction.


2022-09-29 21:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.