Ruby/String/length

Материал из Wiki.crossplatform.ru

Версия от 17:56, 13 сентября 2010; ViGOur (Обсуждение | вклад)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Get the longest word

my_array = %w{this is a test of the longest word check}
longest_word = ""
my_array.each do |word|
  longest_word = word if longest_word.length < word.length
end
puts longest_word



Using the length Method of the String Class

puts "This is a test".length