Example usage for java.lang StringBuilder deleteCharAt

List of usage examples for java.lang StringBuilder deleteCharAt

Introduction

In this page you can find the example usage for java.lang StringBuilder deleteCharAt.

Prototype

@Override
public StringBuilder deleteCharAt(int index) 

Source Link

Usage

From source file:net.certiv.antlr.project.util.Strings.java

public static String camelCase(String in) {
    StringBuilder sb = new StringBuilder(in);
    for (int idx = sb.length() - 1; idx >= 0; idx--) {
        char c = sb.charAt(idx);
        if (c == '_') {
            sb.deleteCharAt(idx);
            sb.setCharAt(idx, Character.toUpperCase(sb.charAt(idx)));
        } else if (Character.isUpperCase(c)) {
            sb.setCharAt(idx, Character.toLowerCase(c));
        }/*from   www  . ja va  2 s .com*/
    }
    sb.setCharAt(0, Character.toLowerCase(sb.charAt(0)));
    return sb.toString();
}

From source file:Main.java

/**
 * Trim all occurrences of the supplied leading character from the given String.
 * @param str the String to check/*  w  w  w  . j a  va 2s.com*/
 * @param leadingCharacter the leading character to be trimmed
 * @return the trimmed String
 */
public static String trimLeadingCharacter(String str, char leadingCharacter) {
    if (!hasLength(str)) {
        return str;
    }
    StringBuilder sb = new StringBuilder(str);
    while (sb.length() > 0 && sb.charAt(0) == leadingCharacter) {
        sb.deleteCharAt(0);
    }
    return sb.toString();
}

From source file:com.kevinshen.beyondupnp.util.Utils.java

/**
 * Returns MAC address of the given interface name.
 *
 * @param interfaceName eth0, wlan0 or NULL=use first interface
 * @return mac address or empty string//  w ww  .  j  a v a 2s. com
 */
public static String getMACAddress(String interfaceName) {
    try {
        List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface intf : interfaces) {
            if (interfaceName != null) {
                if (!intf.getName().equalsIgnoreCase(interfaceName))
                    continue;
            }
            byte[] mac = intf.getHardwareAddress();
            if (mac == null)
                return "";
            StringBuilder buf = new StringBuilder();
            for (int idx = 0; idx < mac.length; idx++)
                buf.append(String.format("%02X:", mac[idx]));
            if (buf.length() > 0)
                buf.deleteCharAt(buf.length() - 1);
            return buf.toString();
        }
    } catch (Exception ex) {
    } // for now eat exceptions
    return "";
}

From source file:com.wiiyaya.framework.common.utils.NumberFormatUtils.java

private static void removeLstZero(StringBuilder sb, String[] numCn) {
    if (sb.length() > 1 && sb.substring(sb.length() - 1).equals(numCn[0])) {
        sb.deleteCharAt(sb.length() - 1);
        removeLstZero(sb, numCn);//from w w w  . j  ava 2s . co  m
    }
}

From source file:Main.java

/**
 * Trim leading whitespace from the given String.
 * @param str the String to check//ww  w  .j  a va2s  .  c o m
 * @return the trimmed String
 * @see java.lang.Character#isWhitespace
 */
public static String trimLeadingWhitespace(String str) {
    if (!hasLength(str)) {
        return str;
    }
    StringBuilder sb = new StringBuilder(str);
    while (sb.length() > 0 && Character.isWhitespace(sb.charAt(0))) {
        sb.deleteCharAt(0);
    }
    return sb.toString();
}

From source file:com.jayway.restassured.internal.print.ResponsePrinter.java

private static String toString(Headers headers) {
    if (!headers.exist()) {
        return "";
    }//from w w  w.  j ava 2  s  . com

    final StringBuilder builder = new StringBuilder();
    for (Header header : headers) {
        builder.append(header.getName()).append(HEADER_NAME_AND_VALUE_SEPARATOR).append(header.getValue())
                .append("\n");
    }
    builder.deleteCharAt(builder.length() - 1);
    return builder.toString();
}

From source file:Main.java

public static String textToString(Reader xquery) throws IOException {
    StringBuilder sb = new StringBuilder();
    BufferedReader br = new BufferedReader(xquery);
    String NL = System.getProperty("line.separator");
    String line = null;/*  w ww.  j  a v a 2  s  .  c o m*/
    try {
        while ((line = br.readLine()) != null) {
            sb.append(line).append(NL);
        }
        sb.deleteCharAt(sb.length() - 1);
    } finally {
        br.close();
    }
    return sb.toString();
}

From source file:Dengue.CDengueManager.java

public static void loadDengueCluster() {

    List<CDengueCluster> lstCluster = new ArrayList<>();

    String strJson = "";

    try {/* w w w.j  a  v a 2 s  . c o  m*/
        strJson = CNetworkFactory.createDengueClusterRequest().sendRequest();
    } catch (IOException ex) {
    }

    if (strJson.isEmpty()) {
        return;
    }

    JSONArray objArray = new JSONObject(strJson).getJSONArray("SrchResults");

    int intCount = objArray.getJSONObject(0).getInt("FeatCount");

    for (int intCounter = 1; intCounter <= intCount; intCounter++) {
        lstCluster.add(CDengueFactory.loadCluster(objArray.getJSONObject(intCounter)));
    }

    StringBuilder objSB = new StringBuilder();

    objSB.append("[");

    for (CDengueCluster objCluster : lstCluster) {
        objSB.append(objCluster.toJSON());
        objSB.append(",");
    }

    objSB.deleteCharAt(objSB.lastIndexOf(","));

    objSB.append("]");

    sendInfoToCPU(objSB.toString(), 33009);

}

From source file:koubachi.internal.json.JSONFactory.java

private static String getSubOfMatch(Matcher matcher) {
    StringBuilder sb = new StringBuilder(matcher.group(0));
    sb.deleteCharAt(sb.length() - 3);
    return sb.toString();
}

From source file:com.wiiyaya.framework.common.utils.NumberFormatUtils.java

private static void removeFstOne(StringBuilder sb, String[] numCn, String[] digitCnLow) {
    if (sb.length() > 1 && sb.substring(0, 2).equals(numCn[1] + digitCnLow[1])) {
        sb.deleteCharAt(0);
    }/* w  w  w .  j  a  v  a2  s  . c  o m*/
}