Example usage for java.util StringTokenizer StringTokenizer

List of usage examples for java.util StringTokenizer StringTokenizer

Introduction

In this page you can find the example usage for java.util StringTokenizer StringTokenizer.

Prototype

public StringTokenizer(String str, String delim) 

Source Link

Document

Constructs a string tokenizer for the specified string.

Usage

From source file:Main.java

/**
 * Remove leading a trailing whitespace characters from each line of input
 * @param input/*from w ww.ja  va  2s  .  c  om*/
 * @return
 */
public static String trim(String input) {
    final String newlineDelimiters = "\n\r\f";

    StringBuilder ret = new StringBuilder();
    StringTokenizer st = new StringTokenizer(input, newlineDelimiters);
    while (st.hasMoreTokens()) {
        ret.append(st.nextToken().replaceAll("^\\s+", "").replaceAll("\\s+$", ""));
        ret.append('\n');
    }
    return ret.toString();
}

From source file:Main.java

public static int[] getIntArray(Context ctx, String prefsKey, String key) {
    StringTokenizer st = new StringTokenizer(
            (TextUtils.isEmpty(prefsKey) ? getPrefManager(ctx) : getPrefs(ctx, prefsKey)).getString(key, ""),
            ",");
    int[] savedList = new int[st.countTokens()];
    for (int i = 0; i < savedList.length; i++) {
        savedList[i] = Integer.parseInt(st.nextToken());
    }/* w  w w.  j a v  a  2  s  .c om*/
    return savedList;
}

From source file:Main.java

public static List<String> parseStringList(String l, String separator) {
    List<String> tmp = new LinkedList<String>();
    StringTokenizer tok = new StringTokenizer(l, separator);
    String t;/*from w  w w  .  j  av a2 s .  co  m*/

    while (tok.hasMoreTokens()) {
        t = tok.nextToken();
        tmp.add(t.trim());
    }

    return tmp;
}

From source file:Main.java

private static boolean initOpenCVLibs(String Libs) {
    Log.d(TAG, "Trying to init OpenCV libs");

    boolean result = true;

    if ((null != Libs) && (Libs.length() != 0)) {
        Log.d(TAG, "Trying to load libs by dependency list");
        StringTokenizer splitter = new StringTokenizer(Libs, ";");
        while (splitter.hasMoreTokens()) {
            result &= loadLibrary(splitter.nextToken());
        }/*from w  w w  . j  a  va  2  s. c om*/
    } else {
        // If dependencies list is not defined or empty.
        result &= loadLibrary("opencv_java3");
    }

    return result;
}

From source file:Main.java

private static boolean initOpenCVLibs(String Libs) {
    Log.d(TAG, "Trying to init OpenCV libs");

    boolean result = true;

    if ((null != Libs) && (Libs.length() != 0)) {
        Log.d(TAG, "Trying to load libs by dependency list");
        StringTokenizer splitter = new StringTokenizer(Libs, ";");
        while (splitter.hasMoreTokens()) {
            result &= loadLibrary(splitter.nextToken());
        }//from  www  .  j  av a  2 s .c om
    } else {
        // If dependencies list is not defined or empty.
        result &= loadLibrary("opencv_java");
    }

    return result;
}

From source file:Main.java

public static String getIdentifier(HashMap<String, ArrayList<String>> addresses) {
    String wifi_address = addresses.get("eth0").get(0); //for now we expect there to be only 1 address, the one OLSRd has assigned
    //need to extract the 3rd and 4th octet of the address
    StringTokenizer tokens = new StringTokenizer(wifi_address, ".");
    tokens.nextElement();/*from w  w w .  j  a  v  a2  s  .  co m*/
    tokens.nextElement();
    String identifier = tokens.nextToken() + "." + tokens.nextToken();
    return identifier;
}

From source file:Main.java

public static String restoreWithEndnote(String text, String holderString, String replacement, String noteTag,
        String noteSplit) {//  www  . ja  va  2 s . com
    int start = text.lastIndexOf(noteTag);
    String note = text.substring(start);
    text = text.substring(0, start);
    if (note.length() == noteTag.length())
        return text;
    StringBuilder sb = new StringBuilder(text);
    StringTokenizer token = new StringTokenizer(note.substring(1), noteSplit);
    int[] index = new int[token.countTokens()];
    for (int i = index.length - 1; i >= 0; i--) {
        index[i] = Integer.parseInt(token.nextToken());
    }

    int h_length = holderString.length();
    for (int i = 0; i < index.length; i++) {
        sb.replace(index[i], index[i] + h_length, replacement);
    }
    return sb.toString();
}

From source file:Main.java

public static String getEventOfExpression(String expression) {
    // pattern for events
    Pattern eventPattern = Pattern.compile("^[\\w\\W&&[^/\\[\\]]]+(\\[[\\w\\W&&[^\\[\\]]]+\\])?(/[\\w\\W]+)?$");
    Matcher eventMatcher = eventPattern.matcher(expression);
    if (eventMatcher.find() && (eventMatcher.group().length() == expression.length())) {
        StringTokenizer st = new StringTokenizer(expression, "[]/");
        return st.nextToken();
    }//  w w  w. j a v  a 2 s . c om
    return null;
}

From source file:Main.java

public static void appendParamValues(StringBuffer params, String tagValues, String tagName, String delim) {
    if (tagValues != null) {
        if (delim == null || delim.trim().length() == 0) {
            delim = ",";
        }/*w  w w.jav  a 2 s  .  c  o m*/
        StringTokenizer st = new StringTokenizer(tagValues.trim(), delim);
        while (st.hasMoreTokens()) {
            params.append("<" + tagName + " id=\"" + encodeStringForXml(st.nextToken().trim()) + "\"></"
                    + tagName + ">");
        }
    }
}

From source file:Main.java

public static String getBuildVersionRelease() {
    String version = "";
    try {/* ww  w .j a  va 2  s.c o  m*/
        String release = Build.VERSION.RELEASE;
        StringTokenizer st = new StringTokenizer(release, ".");
        boolean first = true;
        while (st.hasMoreElements()) {
            String number = st.nextToken();
            if (number != null)
                number = number.substring(0, 1);
            version = (first) ? number : version + "." + number;
            first = false;
        }
    } catch (Exception e) {
    }
    return version;
}