Example usage for java.lang String indexOf

List of usage examples for java.lang String indexOf

Introduction

In this page you can find the example usage for java.lang String indexOf.

Prototype

public int indexOf(String str) 

Source Link

Document

Returns the index within this string of the first occurrence of the specified substring.

Usage

From source file:Main.java

public static String getCPUInfo() {
    RandomAccessFile reader = null;
    try {// w  w w.  j  a  v  a 2s . c o m
        byte[] bs = new byte[1024];
        reader = new RandomAccessFile("/proc/cpuinfo", "r");
        reader.read(bs);
        String ret = new String(bs);
        int index = ret.indexOf(0);
        return index != -1 ? ret.substring(0, index) : ret;
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (reader != null)
                reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return null;
}

From source file:Main.java

public static Map<String, String> split(final List<String> list, final String separator) {
    if (list == null) {
        return null;
    }//from  w  ww  .  j a  v  a  2  s.  c  o m
    final Map<String, String> map = new HashMap<String, String>();
    if (list == null || list.size() == 0) {
        return map;
    }
    for (final String item : list) {
        final int index = item.indexOf(separator);
        if (index == -1) {
            map.put(item, "");
        } else {
            map.put(item.substring(0, index), item.substring(index + 1));
        }
    }
    return map;
}

From source file:Main.java

public static byte[] IpPortStringToBytes(String ipportString) {
    String[] strs = ipportString.substring(0, ipportString.indexOf(":")).split("[.]");
    byte[] b = new byte[strs.length + 2];
    int index = 0;

    for (String str : strs) {
        b[index++] = (byte) (Integer.parseInt(str));
    }//ww  w .  j  av  a  2s.  co  m
    String[] port = ipportString.split("[:]");
    b[index++] = (byte) ((Integer.parseInt(port[1]) & 0x00FF));
    b[index++] = (byte) ((Integer.parseInt(port[1]) & 0xFF00) >> 8);
    return b;
}

From source file:boa.BoaMain.java

protected static String jarToClassname(final File f) {
    String s = f.getName();
    if (s.indexOf('.') != -1)
        s = s.substring(0, s.lastIndexOf('.'));
    return pascalCase(s);
}

From source file:Main.java

private static boolean is_part_of(String[] parts, String of) {
    for (int i = 0; i < parts.length; i++)
        if (of.indexOf(parts[i]) != -1)
            return true;

    return false;

}

From source file:Main.java

public static String removeDashFromString(String str) {

    while (str.contains("-")) {
        str = str.substring(0, str.indexOf('-')) + str.substring(str.indexOf('-') + 1, str.length());
    }//from  w w w  . j  a  v a2 s.com
    return str;
}

From source file:Main.java

public static String removeWhiteSpacesFromTag(String tag) {
    int index = tag.indexOf('/');
    if (index == -1) {
        return tag.trim();
    } else {/*from   ww  w. ja v  a 2 s.c  om*/
        final StringBuilder result = new StringBuilder();
        int index0 = 0;
        while (true) {
            String subtag = (index == -1) ? tag.substring(index0).trim() : tag.substring(index0, index).trim();
            if (subtag.length() > 0) {
                if (result.length() > 0) {
                    result.append("/");
                }
                result.append(subtag);
            }
            if (index == -1) {
                break;
            }
            index0 = index + 1;
            index = tag.indexOf('/', index0);
        }
        return result.toString();
    }
}

From source file:Main.java

public static int[] calculateTextStartEnd(String strings, String target) {
    int[] result = new int[2];
    result[0] = strings.indexOf(target);
    result[1] = result[0] + target.length();
    return result;
}

From source file:Main.java

public static Map<String, String> split(List<String> list, String separator) {
    if (list == null) {
        return null;
    }// www.j a  va  2 s.  c o m
    Map<String, String> map = new java.util.HashMap<String, String>();
    if (list == null || list.size() == 0) {
        return map;
    }
    for (String item : list) {
        int index = item.indexOf(separator);
        if (index == -1) {
            map.put(item, "");
        } else {
            map.put(item.substring(0, index), item.substring(index + 1));
        }
    }
    return map;
}

From source file:at.tugraz.sss.serv.SSMediaWikiU.java

public static String wikiContent(String xmlString) {

    int startIndex = xmlString.indexOf(revStart);
    int endIndex = xmlString.indexOf(revEnd);

    if (startIndex != -1 && endIndex != -1) {
        return StringEscapeUtils.unescapeHtml4(xmlString.substring(startIndex + revEnd.length(), endIndex));
    }/*from   w ww  .  ja  v  a2s.c o m*/

    return null;
}