Check Substring in Java
public static void main(String aa[])
{
String name = "hello";
String s_str="hel";
int flag=0;
int len, len1,m;
len= name.length();
len1= s_str.length();
char arr[]=new char[len];
char s_arr[] = new char[len1];
for(int k=0;k<len;k++)
{
arr[k]= name.charAt(k);
}
for(int k=0;k<len1;k++)
{
s_arr[k]= s_str.charAt(k);
}
for(int i=0;i<len;i++)
{
if(arr[i]==s_arr[0])
{
m=i;
for(int j=0;j<len1;j++)
{
if(s_arr[j]==arr[i])
{
flag=flag+1;
i=i+1;
}
}
if(flag==len1)
{
System.out.println("Sub Srting Exists");
}
else
{
flag=0;
i=m;
}
}
}
}
}
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment