How to convert test's to test\'s

Hi friends

 I want to replace every occurrence  of ' to \' in a string . how to

do it . I know i have to use sub method of string . i don’t know how to
use it .