hey there, So I was completeing an assingment in codecademey involving searching for a certain string of letters in a bigger string of letters.
if(text[i] === “S”&&text[i+1] === “o”&&text[i+2]===“n”){
for(j=i;j<(i+myName.length);j++)
{
hits.push(text[j]);
}
The string I was looking for in this example was “Son” i was simpling using for loops to scan the text and look for this string. And then I was using .push to add the letters into an array.
BUT. i want to make this code more universal. I want to be able to enter any string, and have my code find that in a jungle of random text.
But what i sooon found out was that to achieve this I would need to create a varying if…else statement. An if statement which could increase or decease its conditions depening on how many letters were in the string that I was searching for.
So is this even possible? And if so How could I achieve it?
And, if a varying if…else statement is not possible, how can I do this? Assuming that there is no limit to the search string, and no limit to the text?
This is javascript, but im sure the process for doing it should be the same in many other languages, just different syntax.