Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

ruby replace first character in string

To replace the first two characters of a string with 'Hello':

x = "This is a test"
puts x.sub(/^../, 'Hello')
Comment

PREVIOUS NEXT
Code Example
Ruby :: find path of module in ruby 
Ruby :: rails video_tag with <source 
Ruby :: ruby each with index 
Ruby :: rails on_delete cascade not working 
Ruby :: ruby generate random number 
Ruby :: ruby regexp match all 
Ruby :: ruby 2 decimal 
Ruby :: rails change date format 
Ruby :: rails datatypes 
Ruby :: ruby ||= 
Ruby :: ruby hash merge 
Ruby :: ruby get the number of same element in array 
Ruby :: ruby pop array 
Ruby :: ruby array append vs push 
Ruby :: rails route list 
Ruby :: rails check if a URL is valid 
Ruby :: how to get fields of a table in rails 
Ruby :: ruby empty array 
Ruby :: ruby remove value from array 
Ruby :: ruby get instance variables without accessor 
Ruby :: ruby lambda function 
Ruby :: object service 
Ruby :: ruby for programmers 
Ruby :: httparty headers 
Ruby :: run a specific delayed job from console 
Ruby :: rails render json only some attributes 
Ruby :: ruby rails update email skip confirm email 
Ruby :: singning in using username rails 
Ruby :: In Jekyll - get the parent url path of a collection 
R :: convert list to dataframe r 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =