Latest web development tutorials

Java regionMatches () metoda

Klasa String Java Klasa String Java


Metoda regionMatches () do wykrywania region w dwa ciągi są równe.

gramatyka

public boolean regionMatches(int toffset,
                             String other,
                             int ooffset,
                             int len)

或

public boolean regionMatches(boolean ignoreCase,
                             int toffset,
                             String other,
                             int ooffset,
                             int len)

parametry

  • ignoreCase - Jeśli to prawda, postać Porównanie zignorować sprawę.

  • toffset - Podstawą zrównoważyć ten ciąg neutronową region.

  • inne - argument ciąg.

  • toffset - Początkowy offset parametr ciąg neutronów region.

  • len - liczba znaków do porównania.

Wartość zwracana

Jeśli podasz podregion napisu dopasowuje parametr ciąg określa podregionu, zwraca true; w przeciwnym wypadku false. Zastępuje dokładnie lub rozważyć przypadek zależy parametry ignoreCase.

Przykłady

public class Test {
	public static void main(String args[]) {
		String Str1 = new String("www.w3big.com");
		String Str2 = new String("w3big");
		String Str3 = new String("w3big");

		System.out.print("返回值 :" );
		System.out.println(Str1.regionMatches(4, Str2, 0, 5));

		System.out.print("返回值 :" );
		System.out.println(Str1.regionMatches(4, Str3, 0, 5));

		System.out.print("返回值 :" );
		System.out.println(Str1.regionMatches(true, 4, Str3, 0, 5));
	}
}

Powyższe wyniki wykonania programu:

返回值 :true
返回值 :false
返回值 :true

Klasa String Java Klasa String Java