美文网首页工作
regionMatches方法说明

regionMatches方法说明

作者: sweetMemories | 来源:发表于2017-06-21 17:02 被阅读37次

    regionMatches方法说明

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

    上述两个方法用来比较两个字符串中指定区域的子串。入口参数中,用toffset和ooffset分别指出当前字符串中的子串起始位置和要与之比较的字符串中的子串起始地址;len指出比较长度。前一种方法可区分大写字母和小写字母,如果在 boolean ignoreCase处写true,表示将不区分大小写,写false则表示将区分大小写。而后一个方法认为大小写字母有区别。

    范例:

    String s = "abcdefg";
    String s2 = "Cde";
    System.out.println(s.regionMatches(true,2,s2,0,2));
    输出为true,解释:从s[2]开始查找,匹配s2[0]开始的长度为2的内容,如果内容相同则为true,参数中的第一个true为不区分大小写

    相关文章

      网友评论

        本文标题:regionMatches方法说明

        本文链接:https://www.haomeiwen.com/subject/ntstcxtx.html