我找到了这个android方法TextUtils.regionMatches
但是由于某些原因,这个函数是如何工作的还不清楚。
可以在以下位置找到该函数:http://developer.android.com/reference/android/text/TextUtils.html#regionMatches%28java.lang.CharSequence,%20int,%20java.lang.CharSequence,%20int,%20int%29
这里这个方法的基本代码是http://androidxref.com/4.1.1/xref/frameworks/base/core/java/android/text/TextUtils.java#220
感谢那些可能对该函数的调用方式有所了解的人。
发布于 2012-09-14 19:42:08
public static boolean regionMatches (CharSequence one,
int toffset, CharSequence two, int ooffset, int len)示例代码:
CharSequence one = "asdfQWERTYc1234";
CharSequence two = "ghjklzxcQWERTYg7890kl";
boolean match = TextUtils.regionMatches(one, 4, two, 8, 6);匹配为true。
说明:
在字符序列1中,从toffset (4)开始,并获得等于len (6) => QWERTY的字符数
在字符序列2中,从ooffset (8)开始,并获得等于len (6) => QWERTY的字符数
两个字符序列都匹配,因此该方法返回true。
发布于 2016-01-19 23:46:30
我写这篇文章只是为了在字符串的第一个地方检查"http“,另一个例子对访问者总是有帮助的。
url = "url.without/protocol.info"; // will match
// url = "http://url.with/protocol.info"; // won't match
String match = "http";
if(!url.regionMatches(true, 0, match, 0, match.length())) {
//do something
}https://stackoverflow.com/questions/12423449
复制相似问题