private int findKeyword(String statement, String goal, int startPos){
int spot = -1;
statement = statement.toLowerCase();
goal = goal.toLowerCase();
String word = "";
if(statement.indexOf(goal) == 0){
word = statement.substring(statement.indexOf(goal), statement.indexOf(goal) + 1 + goal.length());
word = word.toLowerCase();
if(word.equals(goal + " ")){
spot = statement.indexOf(goal);
System.out.println("test1");
}
else{
spot = -1;
}
}
else if(statement.indexOf(goal) == statement.length() - goal.length()-1){
word = statement.substring(statement.indexOf(goal) - 1, goal.length() + statement.indexOf(goal));
word.toLowerCase();
if (word.equals(" " + goal)){
spot = statement.indexOf(goal);
System.out.println("test2");
}
else{
spot = -1;
}
}
else if(statement.indexOf(goal) != -1 && spot == -1) {
word = statement.substring(statement.indexOf(goal) - 1, goal.length() + statement.indexOf(goal) + 1);
word.toLowerCase();
if (word.equals(" " + goal + " ") || word.equals(goal + " ") || word.equals(" " + goal + ".") ||word.equals(goal + ".")){
spot = statement.indexOf(goal);
System.out.println("test3");
}
else{
spot = -1;
}
}
/*
if(statement.indexOf(goal) == -1){
spot = -1;
}
*/
return spot;
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.