红宝石 - 整型转换为字符串 [英] Ruby - Convert Integer to String

查看:97
本文介绍了红宝石 - 整型转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ruby中,试图打印出一个字符串中的单个元素是给我找麻烦。相反,看到每个人物的,我看到他们的ASCII值来代替:

In Ruby, trying to print out the individual elements of a String is giving me trouble. Instead of seeing each character, I'm seeing their ASCII values instead:

>> a = "0123"
=> "0123"
>> a[0]
=> 48

我在网上看了,但找不到任何办法让原来的0背出来。我有点新的Ruby,我知道它要的东西简单,但我似乎无法找到它。

I've looked online but can't find any way to get the original "0" back out of it. I'm a little new to Ruby to I know it has to be something simple but I just can't seem to find it.

推荐答案

或者你也可以整数转换为其字符值:

Or you can convert the integer to its character value:

a[0].chr

这篇关于红宝石 - 整型转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆