Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

ruby replace words in a string

# Replace first value a return new string
sentence = 'pop poper'
sentence.sub('pop', 'stop')
=> 'stop poper'
puts sentence
=> 'pop poper'

# Replace all matches and return new string
sentence = 'pop poper'
sentence.gsub('pop', 'stop')
=> 'stop stoper'
puts sentence
=> 'pop poper'

# Replace first value and update existing string
sentence = 'pop poper'
sentence.sub!('pop', 'stop')
=> 'stop poper'
puts sentence
=> 'stop poper'

# Replace all matches and update string
sentence = 'pop poper'
sentence.gsub!('pop', 'stop')
=> 'stop stoper'
puts sentence
=> 'stop stoper'
Comment

substring replace in ruby

user_input = "mooventhan" 
user_input.gsub!(/moo/, "hel")
print user_input
Comment

replace strring by another string ruby

myString = "Welcome to JavaScript!"

myString["JavaScript"]= "Ruby"

puts myString
=> "Welcome to Ruby!"
Comment

PREVIOUS NEXT
Code Example
Ruby :: rails run rake task 
Ruby :: write heroku logs 
Ruby :: time_ago_in_words for created_at model in rails 
Ruby :: redis localhost url 
R :: dplyr replace na 
R :: r how to import tsv file 
R :: loop through list in r 
R :: if not i startswith r 
R :: r list append 
R :: line split r 
R :: rstudio could not find function ggplot 
R :: how to select certain rows containing a word in r 
R :: rename columns in table r 
R :: expression in r 
R :: switch in r 
R :: how to read multiple csv files from a directory in r 
R :: convert a matrix to a vector in r 
R :: subset row r 
R :: rnorm in r 
R :: R vector all but last 
R :: rename a variable in r 
R :: named list in r 
R :: Score pairs of records probabilistically in r 
R :: Add tab in string r 
R :: faceted bar chart in r 
R :: ggplot2 color gradient 
R :: legend in r 
Rust :: array as a parameter rust 
Rust :: rust read lines from stdin and return a vec 
Rust :: calculator in rust 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =