Update: The code is also available in Python in this entry
public static boolean substr(String inputStr, String subStr){
int length = inputStr.length();
int index = 0;
int check = 0;
boolean found = false;
StringBuffer newString = new StringBuffer();
while (index < length) {
try {
if (inputStr.charAt(index) == subStr.charAt(check)) {
newString.append(inputStr.charAt(index));
check++;
if (newString.toString().equals(subStr)) {
found = true;
break;
}
}
} catch (Exception ex){}
index++;
}
return found;
}
Wednesday, April 22, 2009
Finding a substring in a string
Email the blog author at: nicholaskeytholeong [at] gmail [dot] com
Labels:
Algorithms,
Java
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment