Finalize the code for string replacement in buffer.
Added very lame test.