StringUtils类在Android中不起作用

Ran*_*del 7 android string-utils

我在Android代码中使用StringUtils类.但是生成异常,即找不到类.但是我已经在那个类中使用了jar文件.请帮我!

Mig*_*ero 24

尽量不要使用外部库.总是寻找Android替代方案.

对于这种特定情况,您可以使用: android.text.TextUtils


Ran*_*del 0

我的问题通过以下代码解决,我们不需要使用 StringUtils jar 来添加我们的项目。

我创建了自己的类,即“RanjitString”,替换为 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;
}
}
Run Code Online (Sandbox Code Playgroud)

并直接访问静态方法substringBetween:

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

这段代码对我有用......