ruby-数字、字符串、数组
2015-06-27 15:42
453 查看
#需要操作的字符串如下:
#将上面的网元返回的信息保存在一个多行的字符串中;
#解析字符串,将上面的信息保存在一个二维数组中
#比如 arr0 获取第一行,返回 1 tn12fiu active
#arr0[1] 获取第1行第2列 返回 tn12fiu
puts <<HERE
1 tn12fiu active
3 tn12obu1 active
4 tn54nq2 active
HERE
arr_temp=[]
#p arr_temp
str_temp.each{|line|
arr_temp << line.split(" ") #split(" ")
}
p arr_temp[0]
p arr_temp[1][1]
arr_temp = []
#p arr_temp
str_temp.each{|line|
#将字符串分解为数组#p line.split(" ") #将分解的数组存放在一个大数组中,成为二维数组
arr_temp << line.split(" ")
} #访问二维数组第一个原始小数组
p arr_temp[0] #访问此数组第一个元素 字符串“1”
p arr_temp[0][1]
str_temp.each{
|line|
arr_temp << line.split(" ")
}
p arr_temp[0]
p arr_temp[2][1]
#将上面的网元返回的信息保存在一个多行的字符串中;
#解析字符串,将上面的信息保存在一个二维数组中
#比如 arr0 获取第一行,返回 1 tn12fiu active
#arr0[1] 获取第1行第2列 返回 tn12fiu
puts <<HERE
1 tn12fiu active
3 tn12obu1 active
4 tn54nq2 active
HERE
arr_temp=[]
#p arr_temp
str_temp.each{|line|
arr_temp << line.split(" ") #split(" ")
}
p arr_temp[0]
p arr_temp[1][1]
arr_temp = []
#p arr_temp
str_temp.each{|line|
#将字符串分解为数组#p line.split(" ") #将分解的数组存放在一个大数组中,成为二维数组
arr_temp << line.split(" ")
} #访问二维数组第一个原始小数组
p arr_temp[0] #访问此数组第一个元素 字符串“1”
p arr_temp[0][1]
str_temp.each{
|line|
arr_temp << line.split(" ")
}
p arr_temp[0]
p arr_temp[2][1]
相关文章推荐
- ruby-Hash
- ruby-数组
- 如何在windows上安装saas
- Ruby中的语句中断和返回
- Ruby更改gem source
- ruby git hook
- ruby 基础 Array 与 Hash 相互转换
- 安装ruby新版本(github上的rbenv文档--)
- erlang和ruby互相调用
- windows下搭建Ruby(基于eclipse的环境)开发环境
- osx 编译安装配置 ruby on rails
- Ruby中的Profiling工具
- Ruby中的Profiling工具
- [Ruby on Rails系列]6、一个简单的暗语生成器与解释器(上)
- 如何在Mac OS X上安装 Ruby运行环境
- 用map, next 和 reject 简化代码(ruby)
- Ruby Variable Scope 简单讲解
- ruby脚本,随机生成复杂密码
- Ruby On Rails -- 开发流程
- Ruby On Rails -- Rails的安装