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:StringUtil.java

/**
 * returns the next index of a character from the chars string
 *//*from  w ww  .  j  a  v a2s.c  o m*/
public static int indexFrom(String s, String chars) {
    for (int i = 0; i < s.length(); i++)
        if (chars.indexOf(s.charAt(i)) >= 0)
            return i;
    return -1;
}

From source file:Main.java

public static String readElementValue(String elementName, String s) throws IOException {
    int indexOfElementStart = s.indexOf("<" + elementName);
    if (indexOfElementStart == -1) {
        throw new IOException("Couldn't find element '" + elementName + "'!");
    }/*from w  w  w.  j av  a 2 s  .  c o  m*/
    int indexOfValueStart = s.indexOf(">", indexOfElementStart) + 1;
    if (indexOfElementStart == -1) {
        throw new IOException("Couldn't find element '" + elementName + "'! (couldn't find end of start tag)");
    }
    int indexOfValueEnd = s.indexOf("<", indexOfValueStart);
    if (indexOfElementStart == -1) {
        throw new IOException("Couldn't find element '" + elementName + "'! (couldn't find end tag)");
    }
    return s.substring(indexOfValueStart, indexOfValueEnd);
}

From source file:Main.java

static InetAddress parseLinuxSubnetMask(String line) throws UnknownHostException {
    int e = line.indexOf("broadcast");
    if (e == -1)//from   w w  w. j a va  2s .co m
        return null;
    e--;
    String v = line.substring(line.indexOf("netmask") + 8, e);
    if (v.startsWith("0x")) {
        try {
            long address = Long.parseLong(v.substring(2), 16);
            return InetAddress.getByAddress(new byte[] { (byte) (address >> 24),
                    (byte) ((address >> 16) & 0xff), (byte) ((address >> 8) & 0xff), (byte) (address & 0xff) });
        } catch (NumberFormatException e2) {
        }
    } else {
        return InetAddress.getByName(v);
    }
    return null;
}

From source file:Main.java

static public String getFromXmlField(String inputTXT, String tag) {
    String content = "";
    int idx_sys = inputTXT.indexOf("<" + tag + ">");
    idx_sys += tag.length() + 2; // Go to point beyond title tag...
    content = inputTXT.substring(idx_sys);
    //         System.out.println("Tag: "+tag+" Content is:"+content);
    return content;
}

From source file:Main.java

private static String getHash(String s) {
    if (s.contains("/comment/")) {
        s = s.substring(0, s.indexOf("/comment"));
    }/*from w w w .j  a v  a 2s  . com*/
    String next = s.substring(s.lastIndexOf("/"), s.length());
    if (next.contains(".")) {
        next = next.substring(0, next.indexOf("."));
    }
    if (next.startsWith("/")) {
        next = next.substring(1, next.length());
    }
    if (next.length() < 5) {
        return getHash(s.replace(next, ""));
    } else {
        return next;
    }

}

From source file:com.liferay.mobile.sdk.BuilderAntTask.java

protected static Map<String, String> parseArguments(String[] args) {
    Map<String, String> arguments = new HashMap<String, String>();

    for (String arg : args) {
        int pos = arg.indexOf('=');

        if (pos <= 0) {
            throw new IllegalArgumentException("Bad argument " + arg);
        }/*from ww  w. ja  va2  s  . c  om*/

        String key = arg.substring(0, pos).trim();
        String value = arg.substring(pos + 1).trim();

        arguments.put(key, value);
    }

    return arguments;
}

From source file:br.com.ingenieux.mojo.aws.util.CredentialsUtil.java

/**
 * <p> Huge thanks to Eric Hammond from Alestic on this one (source: <a
 * href="http://alestic.com/2009/11/ec2-credentials">Understanding Access Credentials for
 * AWS/EC2</a>: </p>//ww  w .jav  a  2  s . c om
 *
 * <p> (6) AWS Access Key ID and (7) Secret Access Key. This is the first of two pairs of
 * credentials which can be used to access and control basic AWS services through the API
 * including EC2, S3, SimpleDB, CloudFront, SQS, EMR, RDS, etc. Some interfaces use this pair, and
 * some use the next pair below. Pay close attention to the names requested. The Access Key ID is
 * 20 alpha-numeric characters like 022QF06E7MXBSH9DHM02 and is not secret; it is available to
 * others in some situations. <b>The Secret Access Key is 40 alpha-numeric-slash-plus characters
 * like <code>kWcrlUX5JEDGM/LtmEENI/aVmYvHNif5zB+d9+ct</code> and must be kept very secret</b>.
 * </p>
 *
 * @param s string to replace
 * @return redacted string
 */
public static String redact(String s) {
    s = defaultString(s);

    if (-1 != s.indexOf("git-")) {
        return s;
    }

    return s.replaceAll("[\\p{Alnum}\\/\\+]{40}", "/***REDACTED POSSIBLE AWS CREDENTIAL***/");
}

From source file:mergedoc.Application.java

/**
 * ? Look & Feel ???/*from   w  w w.j a  v  a 2  s  .  c o  m*/
 * @throws ClassNotFoundException LookAndFeel ????????
 * @throws InstantiationException ????????????
 * @throws IllegalAccessException ????????????
 * @throws UnsupportedLookAndFeelException lnf.isSupportedLookAndFeel() ? false ??
 */
private static void initSystemLookAndFeel() throws ClassNotFoundException, InstantiationException,
        IllegalAccessException, UnsupportedLookAndFeelException {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    Toolkit.getDefaultToolkit().setDynamicLayout(true);

    // Windows ???
    String osName = System.getProperty("os.name", "");
    if (osName.indexOf("Windows") != -1) {

        Object propoFont = new FontUIResource("MS UI Gothic", Font.PLAIN, 12);
        Object fixedFont = new FontUIResource("MS Gothic", Font.PLAIN, 12);

        // ??????????
        // ????? instanceof FontUIResource ?
        // ???UIDefaults ? Lazy Value ??????
        for (Object keyObj : UIManager.getLookAndFeelDefaults().keySet()) {
            String key = keyObj.toString();
            if (key.endsWith("font") || key.endsWith("Font")) {
                UIManager.put(key, propoFont);
            }
        }

        // ?????
        UIManager.put("OptionPane.messageFont", fixedFont);
        UIManager.put("TextPane.font", fixedFont);
        UIManager.put("TextArea.font", fixedFont);
    }
}

From source file:Main.java

public static String getDisplayName() {
    String email = getPreferredEmail();
    return prefs.getString("display_name", email.substring(0, email.indexOf('@')));
}

From source file:Main.java

/**
 * Extract default values of variables defined in the given string.
 * Default values are used to populate the variableDefs map.  Variables
 * already defined in this map will NOT be modified.
 *
 * @param string string to extract default values from.
 * @param variableDefs map which default values will be added to.
 *//*from  w ww  .j  a v  a  2s.  c o m*/
public static void extractVariableDefaultsFromString(String string, Map<String, String> variableDefs) {
    Matcher variableMatcher = variablePattern.matcher(string);
    while (variableMatcher.find()) {
        String varString = variableMatcher.group(1);

        int eqIdx = varString.indexOf("=");

        if (eqIdx > -1) {
            String varName = varString.substring(0, eqIdx).trim();

            if (!variableDefs.containsKey(varName))
                variableDefs.put(varName, varString.substring(eqIdx + 1, varString.length()));
        }
    }
}