java.lang.String.regionMatchesメソッドの使用

1265 ワード

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 s1= “tsinghua” 
String s2=“it is TsingHua”; 
s1.regionMatches(0,s2,6,7); 
         s1     0   “t”   s2     6   “T”      ,   7   ,       ,     false。 
           : 
s1.regionMatches(true,0,s2,6,7); 
    true,       true         。
                                 ,        :
private static boolean endsWith(String str, String suffix, boolean ignoreCase)
    {
        if(str == null || suffix == null)
            return str == null && suffix == null;
        if(suffix.length() > str.length())
        {
            return false;
        } else
        {
            int strOffset = str.length() - suffix.length();
            return str.regionMatches(ignoreCase, strOffset, suffix, 0, suffix.length());
        }
    }