-
ucwords
Posted on July 13th, 2009 1 commentThe ucwords() function turns the first character of each word in a string to upper-case, if the first character is alphabetic.
PHP
echo ucwords("ruby is easy."); => // Ruby Is Easy.
Ruby doesn’t have a function which can capitalize all the words in a string - so to accomplish this it’s a little bit harder. You need to split the string into words, then capitalize the first character of each word, and then finally join all the words back into a string.
Ruby
puts "ruby is easy.".split(' ').select {|w| w.capitalize! || w }.join(' '); => # Ruby Is Easy.
-
lcfirst
Posted on July 10th, 2009 2 commentsThe lcfirst() function returns a string, with the first character in lower case - only if the first character is alphabetic.
PHP
echo lcfirst("Java is OK."); => // java is OK.
Ruby
my_string = "Java is OK."; puts my_string[0,1].downcase + my_string[1..-1]; => # java is OK.
-
ucfirst
Posted on July 7th, 2009 No commentsThe ucfirst function returns a string, with the first character capitalized - only if the first character is alphabetic.
PHP
echo ucfirst("ruby is great!"); => // Ruby is great!
Ruby
puts "ruby is great!".capitalize => # Ruby is great!
-
strtoupper
Posted on March 31st, 2009 No commentsReturns the argument provided with all alphabetic characters converted to uppercase.
PHP
echo strtoupper('Ruby is pure OO'); // => RUBY IS PURE OO
Ruby
puts 'Ruby is pure OO'.upcase; # => RUBY IS PURE OO
-
strtolower
Posted on March 8th, 2009 No commentsReturns the argument provided with all alphabetic characters converted to lowercase.
PHP
echo strtolower('Ruby is pure OO'); // => ruby is pure oo
Ruby
puts 'Ruby is pure OO'.downcase; # => ruby is pure oo


