Java String regionMatches(boolean ignoreCase)Example
String class regionMatches(boolean ignoreCase) method example
String class regionMatches(boolean ignoreCase) method example. This example shows you how to use regionMatches(boolean ignoreCase) method.This method Tests if two string regions are equal.
Here is the code:-
/**
* @(#) RegionMatchesstring.java
*Program that Tests if two string regions are equal or not.
* @Version 02-May-2008
* @author Rose India Team
*/
public class RegionMatchesstring
{
public static void main(String[] args)
{
String str1 = "Welcome to RoseIndia";
String str2 = "I works with RoseIndia";
/* Determine whether characters from index 11 to 19 in str1 match characters from index 13 to 21 in str2, ignoring the
case of the letters.*/
//regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
boolean match1 = str1.regionMatches(true, 11, str2, 13, 9);
// Determine whether characters 9 through 15 in str1
// match characters 15 through 20 in str2, ignoring the
// case of the letters.
boolean match2 = str1.regionMatches(true, 0, str2, 2, 6);
// Display the results of the regionMatches method calls.
System.out.println("str1[11 -19] == str2[13 - 21]:-" + match1);
System.out.println("str1[9 - 15] == str2[15 - 20]:- " + match2);
}
} |
null
|