I don't do a lot of Java, but this sounds like a good place to use regular expressions.
For simple text searches like this, it's pretty simple. To search for 'ABC', simply use the regex ABC
. You can search for instances of either 'ABC' or 'DEF' using something like ABC|DEF
. I'm not sure exactly what you want, but if you clarify I can help more.
Java has some classes to evaluate these expressions, as do most programming languages.
import java.util.regex.Pattern;
import java.util.regex.Matcher;
For information about how to use these, see this link It provides pretty much all the information you need including info for understanding regexes.
To learn in more detail about regular expression syntax, go here.
There are other ways to search through strings to find patterns, but regular expressions are uniform across all languages and become more and more useful as patterns you look for become more complex.