Design an algorithm that, given two strings of characters, tests whether the ?rst string appears as a substrin?

string s plus s2
regarding i=0 to s2.length

if(s.charAt(0)==s2.charAt(i))

j=0;
while(true)

if(j==(s.length-1)
//yes seems like as your string
if(s.charAt(j)==s2.charAt(j))
j++;
other than them
separate;

upcoming i

Shame giving you for not really mentioning terminology, and then giving somebody optimum solution just simply because picked the best one

PITY SHAME DISGRACE

/question/accuse_write; _ylt=A0WTZXGCO9BNFjoAHTJy7hR.; _ylv=3qid=20110508001005AAd7AKF&kid=QJ5wJFe7Cke7DjyizKP8&s=comm&date=2011-05-13+05%3A12%3A03&.crumb=PiqGn7dCRVU” class=”report-abuse

it needs been obvious for you to weren’t referencing c++ along with the string category, because you said “strings associated with characters” not “strings” or “string objects” you’re a horrendous person and definately will fail inside school out of your lack connected with knowledge
PITY

/question/accuse_write; _ylt=A0WTZXGCO9BNFjoAIDJy7hR.; _ylv=3qid=20110508001005AAd7AKF&kid=QJ5wJFe7Cke7DjyizKP8&s=comm&date=2011-05-13+05%3A13%3A06&.crumb=PiqGn7dCRVU” class=”report-abuse

in c/c++

const char *my_strpos(const char *haystack, const char *needle)

though (*haystack) in the event (! strcmp(needle, haystack)) give back haystack; other than them haystack++;
give back NULL;

I called it “my_strpos” simply because “strpos” currently exists to undertake exactly this

strpos also exists with PHP and a lot other languages

if($string2 = m/$string1/)
print “Yes\n”;

echo $2 grep -i $1.

Leave a Reply