Mega Code Archive

 
Categories / Ruby / String
 

To replace the first two characters of a string with Hello

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