Bird
0
0

You have a string of words separated by semicolons: "cat;dog;bird". How do you convert it into a string with words separated by spaces instead?

hard📝 Application Q8 of 15
Ruby - String Operations
You have a string of words separated by semicolons: "cat;dog;bird". How do you convert it into a string with words separated by spaces instead?
A"cat;dog;bird".join(' ').split(';')
B"cat;dog;bird".split(';').join(' ')
C"cat;dog;bird".split(' ').join(';')
D"cat;dog;bird".split(';').join(';')
Step-by-Step Solution
Solution:
  1. Step 1: Split string by semicolon

    Splitting by ';' creates an array ["cat", "dog", "bird"].
  2. Step 2: Join array with space

    Joining with ' ' creates "cat dog bird".
  3. Final Answer:

    "cat;dog;bird".split(';').join(' ') -> Option B
  4. Quick Check:

    split(';') then join(' ') replaces semicolons with spaces [OK]
Quick Trick: Split by old separator, join by new one [OK]
Common Mistakes:
  • Reversing split and join
  • Using wrong delimiters
  • Joining with original separator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes