![]() |
The Java Developers Almanac 1.4 |
|
e72. Determining If a String Contains a SubstringSee also e423 Quintessential Regular Expression Search Program. String string = "Madam, I am Adam";
// Starts with
boolean b = string.startsWith("Mad"); // true
// Ends with
b = string.endsWith("dam"); // true
// Anywhere
b = string.indexOf("I am") > 0; // true
// To ignore case, regular expressions must be used
// Starts with
b = string.matches("(?i)mad.*");
// Ends with
b = string.matches("(?i).*adam");
// Anywhere
b = string.matches("(?i).*i am.*");
e71. Comparing Strings e73. Getting a Substring from a String e74. Searching a String for a Character or a Substring e75. Replacing Characters in a String e76. Replacing Substrings in a String e77. Converting a String to Upper or Lower Case e78. Converting a Primitive Type Value to a String e79. Converting Between Unicode and UTF-8 e80. Determining a Character's Unicode Block e81. Determining If a String Is a Legal Java Identifier
© 2002 Addison-Wesley. |