开发者

How to find the length of an array class?

开发者 https://www.devze.com 2023-01-06 14:49 出处:网络
$param开发者_开发技巧 = k.chomp.split(\"\\t\") How can I find the length of $param given that it is an array?
$param开发者_开发技巧 = k.chomp.split("\t")

How can I find the length of $param given that it is an array? actually when I'm writing

puts $param.class

I got the o/p like Array. Now how do I find the length of this array?

I tried $param.length but it's not working.


Ref Array class

k = "This \t is \t just \t testing"
$param=k.chomp.split("\t")
array_length= $param.length   #or $param.size
puts "length of $param is : #{array_length}"

o/p

length of $param is : 4


Try using .size like this:

$param.size
0

精彩评论

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