📜  红宝石 |字符串大写()方法

📅  最后修改于: 2022-05-13 01:55:28.012000             🧑  作者: Mango

红宝石 |字符串大写()方法

capitalize是 Ruby 中的 String 类方法,用于通过将给定字符串的第一个字符转换为大写并将其余字符转换为小写来返回给定字符串的副本。

示例 #1:

# Ruby program to demonstrate
# the capitalize method
  
# Taking the string and
# using the method
puts "geeks".capitalize()
puts "hey".capitalize()

输出:

Geeks
Hey

示例 #2:

# Ruby program to demonstrate
# the capitalize method
  
# Taking a string already in
# uppercase and using the 
# method will give the same
# string
puts "Computer".capitalize()
puts "science".capitalize()

输出:

Computer
Science