algorithm - Write a function which finds a substring in a string and replaces all such occurrences with another string? -


write function finds substring in string , replaces such occurrences string. prototype of function :

      char* findreplace(char* src, char* find, char* replace); 

test case 1:

input:
src[] = "sivasai".
find[] = "as"
replace[] = "asas"

output:
src[] = "sivasasai"

test case 2:
src[] = "sivasai".
find[] = "vasa"
replace[] = "a"

output:
src[] = "siai"

solution should time efficient .

you can use:
1) knuth–morris–pratt algorithm: http://en.wikipedia.org/wiki/knuth-morris-pratt_algorithm
2) boyer-moore algorithm http://en.wikipedia.org/wiki/boyer-moore_string_search_algorithm
3) rabin-karp algorithm http://en.wikipedia.org/wiki/rabin-karp_string_search_algorithm


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -