parse Int among substring - Android java.lang

Android examples for java.lang:Integer

Description

parse Int among substring

Demo Code

import android.util.Log;
import java.net.URLDecoder;
import java.util.Collection;
import java.util.regex.Pattern;

public class Main{

    /**/* ww w.  j  ava 2  s.com*/
     * @param pStr
     * @param pStartIndex
     *            or -1 to parse from complete pStr
     * @param pEndIndex
     * @return int value, parsed from pStr or a substring of pStr
     */
    public static int parseInt(String pStr, int pStartIndex, int pEndIndex) {
        if (pStr == null) {
            return 0;
        }
        try {
            if (pStartIndex == -1) {
                return Integer.parseInt(pStr);
            } else {
                return Integer.parseInt(pStr.substring(pStartIndex,
                        pEndIndex));
            }
        } catch (Exception e) {
            Log.e(LOG_TAG, "parseInt() pStr: " + pStr + ", Start: "
                    + pStartIndex + ", End: " + pEndIndex);
            return 0;
        }
    }

}

Related Tutorials