Ruby/String/String.new

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

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

Содержание

Creating Strings

You can create strings with the new method. 
title = String.new # => ""



length and size methods both return an integer indicating how many characters a string holds.

title = String.new # => ""
title = String.new( "Much Ado about Nothing" )
title = String.new # => ""
title.empty? # => false
title.length # => 22



test a string to see if it is empty before you process it

title = String.new # => ""
title.length [or] title.size # => 0



test a string to see if it is empty with empty?

title = String.new # => ""
title.empty? # => true



The new method can take a string argument

title = String.new # => ""
title = String.new( "Much Ado about Nothing" )
title = String.new # => ""
title.empty? # => false
title.length # => 22