Categories: Java Api

Java regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len) 方法

返回到:Java 介绍String类

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 — 如果为 true,则比较字符时忽略大小写。
  • toffset — 此字符串中子区域的起始偏移量。
  • other — 字符串参数。
  • ooffset — 字符串参数中子区域的起始偏移量。
  • len — 要比较的字符数。

返回值

如果字符串的指定子区域匹配字符串参数的指定子区域,则返回 true;否则返回 false。是否完全匹配或考虑大小写取决于 ignoreCase 参数。

实例

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


  System.out.println("value:");
  System.out.println(Str1.regionMatches(4, Str2, 0, 5));


  System.out.println("value:");
  System.out.println(Str1.regionMatches(4, Str3, 0, 5));


  System.out.println("value:");
  System.out.println(Str1.regionMatches(true, 4, Str3, 0, 5));
 }
}

以上程序执行结果为:

value:
true
value:
false
value:
true

返回到:Java 介绍String类

terry

这个人很懒,什么都没有留下~

Share
Published by
terry

Recent Posts

在 Chrome 中删除、允许和管理 Cookie

您可以选择删除现有 Cooki…

15 小时 ago

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

1 周 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

2 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

2 周 ago

Vue3:手动清理keep-alive组件缓存的方法

Vue3中手动清理keep-a…

3 周 ago

聊聊React和Vue组件更新的实现及区别

React 和 Vue 都是当…

4 周 ago