String Exercises

  1. Visit the official documentation for using Ruby Strings. Get very familiar with this page -- you'll be visiting it frequently! Use the examples and explanations on this page to help you do the next step.

  2. Open pry. Create some strings and try each of the following methods:

    • #length
    • #upcase
    • #downcase
    • #delete
    • #count
    • #gsub
    • #start_with?
    • #reverse
  3. Write a method #capitalize that accepts a string as an argument and capitalizes the first letter of the string. Note: Do not use the built in method String#capitalize

     capitalize("yahoo!") == "Yahoo!"
    
  4. Write a method, #shout_then_whisper that takes in two strings, and shouts the first part, then whispers the second part. The output should look like this:

     shout_then_whisper("Hello", "McDouglas") == "HELLO!! ... mcdouglas"
    
  5. Write a method, #how_long? that accepts a string as an argument. Your method should return a new string in the format:

     how_long?("I am a sentence :)") == "Your string is 18 characters long"
    
  6. Write a method, #hyphenify that accepts a string as an argument. Your method should remove all the spaces and replace them with hyphens.

     hyphenify("I am a sentence!") == "I-am-a-sentence!"
    

results matching ""

    No results matching ""