Ruby program to replace spaces with hyphen in a string


Following program shows you how to replace spaces with hyphen in a string.
In this program we use .gsub to replace spaces with hyphen

input  = "Hello World"
result = input.gsub(" ", "-")
puts "After replacing input string with - is: #{result}"

Output:

After replacing input string with - is: Hello-World