红宝石 |字符串为空?方法
空的?是 Ruby 中的 String 类方法,用于检查字符串长度是否为零。
Syntax: str.empty?
Parameters: Here, str is the given string which is to be checked.
Returns: It returns true if str has a length of zero, otherwise false.
示例 1:
# Ruby program to demonstrate
# the empty? method
# Taking a string and
# using the method
puts "checking".empty?
puts "method".empty?
输出:
false
false
示例 2:
# Ruby program to demonstrate
# the empty? method
# Taking a string and
# using the method
puts "".empty?
puts ".".empty?
输出:
true
false