str1=input('First '); str2=input('second '); n1=length(str1); n2=length(str2); % ind=1; % indication if 0-exists % 1-not exists n=n1-n2+1; % reducing the search % Nested Loops % ============ % External loop for i=1:n if str1(i)==str2(1) % comapring the charcter i'th of str1 % with the first character of str2. % % search where to start the fine search of str2 in str1. ind=0; % the substring is found (the first character is found). % Internal loop for j=1:(n2-1) % The fine search of the substring. if str1(i+j)~=str2(1+j) % is there a character of a substrig that is not if the string str1? ind=1; % the substring doesn't exist break % exit from the loop. end end %j end if ind==0 % If exists? break % exit from the loop end end %i if ind==1 disp(['doesn-t exist']); else disp(['exists']); end