How to determine a string PARTIALLY contains another string ? (preferrable Java) -


i'm doing java project needs determine whether string contains string following below logic:

  • a parent string "this parent string" contais "isstr" should return true. because characters of "isstr" can found in parent string preserving substring order.
  • contains should case-insensitive.

is there kindly me how write logic in simple , efficient way, or library appreciated!

public static void main(string[] args) {     string parentstr = "this parent string", childstr = "isstr";     //turn both lowcase.     parentstr.tolowercase(); childstr.tolowercase();     integer childstrindex = 0;     //run on parent string , if found match keep comparing next     //character in child string.     (int index = 0 ; index < parentstr.length(); index++) {         character currchar = parentstr.charat(index);         if (childstr.length() <= childstrindex)             break;         if (currchar.equals(childstr.charat(childstrindex)))             childstrindex++;     }     // if @ end in last character of child string, true.     if (childstrindex >= childstr.length())         system.out.print(true);     else         system.out.print(false); } 

hope helps. btw sounds homework.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -