Algorithm to find substring within a string or a paragraph
0
/
1993
ID provided is not a Gistpen repo.
Below is the link to compile and execute the above code:
Substring pattern match
Let’s try to understand what the above program does:
It has a nested loop. The outer loop loops through the given string parsing the string character by character.
The inner loop parses the substring character by character and looking for a possible match of it’s first character
to that of the current character of the main string. If the characters match, it does a stnrcmp() wherein it will
compare N characters (N = length of substring) starting from current index and if a match is encountered, the index is
pushed into the array. This iteration goes till the length of the main string.
This algorithm can be further extended to create a find and replace functionality which will be the topic of my next
blog. Stay tuned for more interesting stuff and please comment if there are any doubts in this one.