Phương thức vùng chuỗi JavaMatches ()
Ví dụ
Kiểm tra xem hai vùng chuỗi có bằng nhau không:
String myStr1 = "Hello, World!"; String myStr2 = "New World"; System.out.println(myStr1.regionMatches(7, myStr2, 4, 5)); System.out.println(myStr1.regionMatches(0, myStr2, 0, 5));
Định nghĩa và cách sử dụng
Phương thức regionMatches()
so sánh các vùng trong hai chuỗi khác nhau để kiểm tra xem chúng có bằng nhau hay không.
Cú pháp
Một trong những điều sau đây:
public boolean regionMatches(boolean ignoreCase , int offset , String other , int otherOffset , int length )
public boolean regionMatches(int offset , String other , int otherOffset , int length )
Giá trị tham số
Parameter | Description |
---|---|
ignoreCase | Optional. When true the comparison between regions will be case-insensitive. Defaults to false. |
offset | Required. The position in the string where the region starts. |
other | Required. The string with the other region that is being compared. |
otherOffset | Required. The position in the other string where the region starts. |
length | Required. The size of the regions being compared. |
Chi tiết kỹ thuật
Trả về: | true nếu hai vùng bằng nhau, false nếu không. |
---|---|
Phiên bản Java: | Bất kì |
❮ Các phương thức chuỗi