Ranjitsingh Chandel
Ranjitsingh Chandel

Reputation: 1489

StringUtils class not working in Android

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!

Upvotes: 7

Views: 16622

Answers (2)

Ranjitsingh Chandel
Ranjitsingh Chandel

Reputation: 1489

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...

Upvotes: 0

Miguel Rivero
Miguel Rivero

Reputation: 1466

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

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

Upvotes: 25

Related Questions