US>To view the character code?

Asked 2 years ago, Updated 2 years ago, 67 views

If ruby takes data from the database and puts it into standard output such as p, it will display \xB8\xB8\xB8.

The program itself is working well, but debugging is difficult, so I want to be able to convert it so that I can see it in the standard output, but I don't know how to do it.

Could you please let me know?

Also, I understand that the character code is displayed as it is, is that correct?
Character encoding and I'm having trouble searching.

ruby

2022-09-30 21:14

1 Answers

If p is given a string object, it will appear according to the character encoding that the string object has.

If it appears like \xB8\xB8\xB8, I think the encoding is probably not correct.

For example, if the string is a UTF-8 encoding, you can use p string.dup.force_encoding("utf-8") to display it as a character.


2022-09-30 21:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.