Pregunta

I am using StringUtils class in Android code. but exception generated i.e. class not found. But already i used jar file for that class. Please help me!

¿Fue útil?

Solución 2

My problem solved with following code, We need not use StringUtils jar to add our project.

I create my own class i.e "RanjitString" replace with StringUtils.

public class RanjitString {
public static String substringBetween(String str, String open, String close) {
    if (str == null || open == null || close == null) {
        return null;
    }
    int start = str.indexOf(open);
    if (start != -1) {
        int end = str.indexOf(close, start + open.length());
        if (end != -1) {
            return str.substring(start + open.length(), end);
        }
    }
    return null;
}
}

And directly access the static method substringBetween:

String myxml="This is my xml with different tags";
String successResult = RanjitString.substringBetween(myxml,
                "<tag>", "</tag>");

This code is working for me...

Otros consejos

Try not to use external libraries. Look always for an Android alternative.

For this specific case, you could use: android.text.TextUtils

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top