ruby replace substring code example
Example 1: ruby replace certain character
# Ruby language
str_old = "first-name last-name"
str_old.sub("-", "_") # Replace first "-" with "_"
str_old.gsub("-", "_") # Replace all "-" with "_"
Example 2: replace strring by another string ruby
myString = "Welcome to JavaScript!"
myString["JavaScript"]= "Ruby"
puts myString
=> "Welcome to Ruby!"