李超

cc编程笔记本。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
arr = "1,2,3".split(',')
arr.map!{
|item| item = item.to_i} #一般可以用map!方法来改变原数组内容
0.upto(arr.length-1){|idx|arr[idx] = arr[idx].to_s} #再将数组内容改回字符串形式 使用upto方法


fixnum对象的upto和downto方法,可以很方便的作为访问一个数组的索引。

其实也可以这样做
(0..arr.length-1).each{|n| arr[n] = arr[n].to_i}


总之ruby是想怎么写就怎么写 非常方便
posted on 2008-04-08 09:49  coderlee  阅读(2491)  评论(0编辑  收藏  举报