Java regionMatches () วิธีการ
regionMatches () วิธีการในการตรวจสอบพื้นที่ภายในสองสายมีค่าเท่ากัน
ไวยากรณ์
public boolean regionMatches(int toffset, String other, int ooffset, int len) 或 public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
พารามิเตอร์
IgnoreCase - ถ้าเป็นจริงตัวละครเปรียบเทียบกรณีละเว้น
toffset - เริ่มต้นชดเชยสตริงภูมิภาคนี้นิวตรอน
อื่น ๆ - อาร์กิวเมนต์สตริง
toffset - เริ่มต้นชดเชยพารามิเตอร์สตริงภูมิภาคนิวตรอน
len - จำนวนตัวอักษรเพื่อเปรียบเทียบ
ราคาย้อนกลับ
ถ้าคุณระบุอนุภูมิภาคของสตริงที่ตรงกับพารามิเตอร์สตริงระบุภูมิภาคย่อยก็จะส่งกลับจริงเท็จอย่างอื่น ตรงกันหรือพิจารณากรณีขึ้นอยู่กับพารามิเตอร์ IgnoreCase
ตัวอย่าง
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)); } }
ดังกล่าวข้างต้นผลการทำงานของโปรแกรม:
返回值 :true 返回值 :false 返回值 :true