I know this has question has been asked countless times.. but I can't seem to get it to work. the problems are,
- Even converting everything to lower case doesn't work out when "computer" and "Comp" are entered.
- If the string is a sentence (I add a space), it essentially skips the substring code and says "Not in the string"..
Help is appreciated. thanks!
Scanner in=new Scanner(System.in);
System.out.println("\fEnter the main string:");
String GivenString=in.next();
System.out.println("Enter the substring :");
String SubString=in.next();
GivenString.toLowerCase();
SubString.toLowerCase();
if(GivenString.indexOf(SubString)!=-1)
{
System.out.println("Substring is in the given string.");
}
else
{
System.out.println("Substring is not in the given string.");
}