Bird
0
0

You want to create a Ruby string that exactly contains: He exclaimed, "That's amazing!" Which of the following is the correct way?

hard📝 Application Q8 of 15
Ruby - Variables and Data Types
You want to create a Ruby string that exactly contains: He exclaimed, "That's amazing!" Which of the following is the correct way?
A'He exclaimed, "That\'s amazing!"'
B"He exclaimed, 'That's amazing!'"
C"He exclaimed, \"That's amazing!\""
D'He exclaimed, 'That\'s amazing!''
Step-by-Step Solution
Solution:
  1. Step 1: Understand the string content

    The string contains both single and double quotes.
  2. Step 2: Choose correct quoting and escaping

    Using double quotes to enclose the string and escaping inner double quotes is correct.
  3. Step 3: Verify options

    "He exclaimed, \"That's amazing!\"" correctly escapes inner double quotes and allows single quotes inside.
  4. Final Answer:

    "He exclaimed, \"That's amazing!\"" -> Option C
  5. Quick Check:

    Escape inner double quotes inside double-quoted strings [OK]
Quick Trick: Escape inner quotes matching outer quotes [OK]
Common Mistakes:
  • Not escaping inner double quotes
  • Using mismatched quotes without escape
  • Incorrectly escaping single quotes inside single quotes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes