Ruby has a few methods for changing the case of strings. To convert to lowercase, use downcase
:
"hello James!".downcase #=> "hello james!"
Similarly, upcase
capitalizes every letter and capitalize
capitalizes the first letter of the string but lowercases the rest:
"hello James!".upcase #=> "HELLO JAMES!" "hello James!".capitalize #=> "Hello james!" "hello James!".titleize #=> "Hello James!" (Rails/ActiveSupport only)
If you want to modify a string in place, you can add an exclamation point to any of those methods:
string = "hello James!" string.downcase! string #=> "hello james!"
Refer to the documentation for String for more information.
Related Posts:
- How do I lowercase a string in Python?
- Ignoring upper case and lower case in Java
- What does %w(array) mean?
- How to check whether a string contains a substring in Ruby
- Ruby array to string conversion
- How to delete specific characters from a string in Ruby?
- What does the Ruby method ‘to_sym’ do?
- What is the canonical way to trim a string in Ruby without creating a new string?
- Get underlined text with Markdown
- What is the meaning of *nix?
- Get underlined text with Markdown
- What does the “map” method do in Ruby?
- How to write a switch statement in Ruby
- Rails 5 ActionController::InvalidAuthenticityToken error
- what does ? ? mean in ruby
- How to update Ruby Version 2.0.0 to the latest version in Mac OSX Yosemite?
- How to use “gets” and “gets.chomp” in Ruby
- How do I lowercase a string in C?
- Getting a substring in Ruby by x number of chars
- Ruby: How to install a specific version of a ruby gem?
- ruby operator “=~” [duplicate]
- What is attr_accessor in Ruby?
- ActionController::UnknownFormat
- What does ||= (or-equals) mean in Ruby?
- How to read lines of a file in Ruby
- Array to Hash Ruby
- Ruby: undefined method `[]’ for nil:NilClass when trying to get Enumerator on an Array of Hashes
- How to convert a string to lower case in Bash?
- How to Convert a C++ String to Uppercase
- How to map with index in Ruby?
- Ruby equivalent for Python’s “try”?
- What does “+=” (plus equals) mean?
- Rails 4 RoutingError: No Route Matches
- How to sum array of numbers in Ruby?
- How to check if a value exists in an array in Ruby
- undefined method (NoMethodError) ruby
- Multi-Line Comments in Ruby?
- How to uninstall ruby installed by ruby-install
- PG::ConnectionBad – could not connect to server: Connection refused
- Rails syntax error : unexpected keyword_ensure, expecting end-of-input
- Removing all installed Gems and starting over
- Ruby `send` vs `call` method
- What is the meaning of “do | |” in Ruby?
- RVM is not a function, selecting rubies with ‘rvm use …’ will not work
- Ruby: kind_of? vs. instance_of? vs. is_a?
- Rails: I installed Ruby, now “bundle install” doesn’t work
- How to do a newline in output
- Ruby: What is the easiest way to remove the first element from an array?
- Ruby String to Date Conversion
- p vs puts in Ruby
- Determining type of an object in ruby
- Fizz Buzz in Ruby for dummies
- How to Uninstall RVM? [duplicate]
- What is the “right” way to iterate through an array in Ruby?
- What is the difference between a Process’ pid, ppid, uid, euid, gid and egid?
- Equivalent of “continue” in Ruby
- Difference between map and collect in Ruby?
- Creating and iterating a 2d array in Ruby
- What is the best way to convert an array to a hash in Ruby
- Ruby 2.0.0p0 IRB warning: “DL is deprecated, please use Fiddle”
- Getting error: dyld: Symbol not found: _clock_gettime
- Uninstall old versions of Ruby gems
- Meaning of #{ } in Ruby?
- Uploading a file in Rails
- What is java interface equivalent in Ruby?
- Sort hash by key, return hash in Ruby
- Gem installation error: You have to install development tools first
- How to understand strptime vs. strftime
- How can I delete one element from an array by value
- How to break out from a ruby block?
- ERROR: While executing gem … (Gem::FilePermissionError)
- No such file or directory @ rb_sysopen ruby
- How to add to an existing hash in Ruby
- Ruby ‘require’ error: cannot load such file
- Difference between $stdout and STDOUT in Ruby
- No implicit conversion of String into Integer (TypeError)?
- Multi-Line Comments in Ruby?
- How do I convert a String to an int in Java?
- How to format strings in Java
- How do I get a substring of a string in Python?
- Substring in excel
- Does Python have a string ‘contains’ substring method?
- Why the switch statement cannot be applied on strings?
- How does strtok() split the string into tokens in C?
- Convert bytes to a string
- Java – Convert integer to string [duplicate]
- Replacing instances of a character in a string
- Changing one character in a string
- How to read a file line-by-line into a list?
- What is lexicographical order?
- strip(char) on a string
- How to convert string to char array in C++?
- How can I convert a std::string to int?
- How to convert list to string [duplicate]
- Easiest way to convert int to string in C++
- TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3
- How to check whether a string contains a substring in JavaScript?
- Check if a string has a certain piece of text [duplicate]
- Converting integer to string in Python
- Reverse a string in Python