日期:2014-05-20 浏览次数:20799 次
String text="the background=\"yello\",good color";,这中间X+..就是the ,A是background=\", C是\",..Y是,good color ,那么需要提取的B就是yellow.
public static void main(String[] args) {
String text = "the background=\"yello\",good color";
String A = "background=\"";
String C = "\"";
String B = getParam(text, A, C);
System.out.println("B : " + B);
}
public static String getParam(String src, String findLeft, String findRight) {
int indexFirst = -1;
int indexSecond = -1;
indexFirst = index(src, findLeft, 0);
if (indexFirst >= 0) {
indexSecond = index(src, findRight, indexFirst + findLeft.length());
if (indexSecond >= 0) {
return src.substring(indexFirst + findLeft.length(), indexSecond);
}
}
return null;
}
public static int index(String src, String obj, int indexBegin) {
int indexRet = -1;
for (int i = indexBegin, j = 0; i < src.length(); i++) {
if (src.charAt(i) == obj.charAt(0)) {
while(src.charAt(j + i) == obj.charAt(j++)) {
if (j >= obj.length()) {