I need to create a program that accepts a string input and will highlight certain words that is in my String List.
Example:
String MyList[] = {"Dog","Cat","Lion"};
Sample Input Text: I have a Dog and a Cat and a Lion . "
I dont have problem if the input text doesn't have any new line or escape character but if the input text have new line, this is the result.
Example:
String MyList[] = {"Dog","Cat","Lion"};
Sample Input Text:
I have a Dog
and a Cat
and a Lion
Note: The uppercase character means highligthed character
I have a DOG
and a cAT
and a liON
My Sample Code for Highlighting:
for(String x : MyList)
{
int startOffset = inputText.indexOf(x);
doc.setCharacterAttributes (startOffset,x.length,myStyle,false);
}
I guess the problem is the Newline or escape character but I can't find a way to fix it.
How can I get the correct start offset of the word if ever the input string have new line/s?
Any Idea?