Search code examples
calgorithmstring-search

For string, find and replace


Finding some text and replacing it with new text within a C string can be a little trickier than expected. I am searching for an algorithm which is fast, and that has a small time complexity.

What should I use?


Solution

  • I can't help but wonder what algorithm strstr() implements. Given that these are fairly standard algorithms, it's entirely possible that a good implementation of strstr() uses one of them.

    However there's no guarantee that strstr() implements an optimised algorithm or that the same algorithm is used from one platform to another.