I was looking for the find and replace algorithm which editor softwares are using. for ex: notepad. when i search something and then when i replace it , how exactly it works. I am aware of rabin-karp and KMP algos. but i am wondering if they are most efficient ? and how do they replace it ? Seraching is okay, may be KMP can be applied, but replacing has some cases like when replaced words is of greater length and when it is of smaller length. Can you explain or give some link to it ? how will you shift whole text after that word in efficient way. thanks.