开发者

ROR + Ruby Function To Access Last Value Of An Variable

In Ruby 1.8.6, I want to the last value of any string.

For example : notice_5 here, I want "5" in one of the variable. So please suggest any function through which 开发者_StackOverflow社区I can get 5 in one of the variable.

Thanks


Use index -1

var = "somevar_5"
var[0]
 => "s"
var[-1]       # get character code
 => 53
var[-1].chr   #get character
 => "5"


Got the Solution

>> a = 'hello_7'
=> "hello_7"
>> a.last
=> "7"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜