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

public static URL getString(URL str) {
    String ssString = str.toString();
    String[] aaStrings = ssString.split("/");
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < aaStrings.length; i++) {
        if (i == 4) {
            aaStrings[i] = "180";
        }//from  w  w  w  .  j  ava  2 s.  c om
        sb.append(aaStrings[i] + "/");
    }
    sb.deleteCharAt(sb.length() - 1);
    URL url = null;
    try {
        url = new URL(sb.toString());
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return url;
}

From source file:Main.java

/**
 * @param s A string with commas.//from www .  java  2s .  c o  m
 * @return The same string, a newline appended after every comma.
 */
public static String commaToNewline(String s) {
    StringBuilder sb = new StringBuilder();
    String[] split = s.split(",");
    for (String splitString : split) {
        sb.append(splitString).append(",").append("\n");
    }
    if (sb.length() > 2) {
        sb.deleteCharAt(sb.length() - 2);
    }
    return sb.toString();
}

From source file:Main.java

/**
 * Null-safe method for writing the items of a string array out as a string
 * separated by the given char separator.
 *
 * @param array     the array.//from   ww w .jav a  2  s.  co m
 * @param separator the separator of the array items.
 * @return a string.
 */
public static String toString(String[] array, String separator) {
    StringBuilder builder = new StringBuilder();

    if (array != null && array.length > 0) {
        for (String string : array) {
            builder.append(string).append(separator);
        }

        builder.deleteCharAt(builder.length() - 1);
    }

    return builder.toString();
}

From source file:Main.java

public static <T> String parseArrayToString(T[] imgsIds) {
    StringBuilder stringBuilder = new StringBuilder();
    for (T t : imgsIds) {
        stringBuilder.append(t).append(",");
    }// w  w w .j  a va2 s. c o m
    int index = stringBuilder.lastIndexOf(",");
    if (index == (stringBuilder.toString().length() - 1)) {
        stringBuilder.deleteCharAt(index);
    }
    return stringBuilder.toString();
}

From source file:Main.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 w  w  . j  a v a2 s.  c o  m
 */
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 "";
    /*try {
    // this is so Linux hack
    return loadFileAsString("/sys/class/net/" +interfaceName + "/address").toUpperCase().trim();
    } catch (IOException ex) {
    return null;
    }*/
}

From source file:Main.java

public static String getQuanBuFenLeiName(String[] choices, String defaultQuanbufenlei, String defaultItemName) {

    if (choices.length < 3) {

        return defaultQuanbufenlei;
    }/* ww w . j  a va2 s .  c o  m*/

    if (choices[0].equals(defaultItemName) && choices[1].equals(defaultItemName)
            && choices[2].equals(defaultItemName)) {

        return defaultQuanbufenlei;
    } else {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < choices.length; i++) {

            if (!choices[i].equals(defaultItemName)) {
                sb.append(choices[i] + "/");
            }
        }

        sb.deleteCharAt(sb.length() - 1);
        return sb.toString();
    }

}

From source file:com.weibo.api.motan.config.ConfigUtil.java

public static String extractProtocols(String export) {
    Map<String, Integer> protocols = parseExport(export);
    StringBuilder sb = new StringBuilder(16);
    for (String p : protocols.keySet()) {
        sb.append(p).append(MotanConstants.COMMA_SEPARATOR);
    }//from w w  w.  jav  a 2  s .  co m
    if (sb.length() > 0) {
        sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();

}

From source file:Main.java

public static String paramsmap2ParamsString(Map<String, String> params) {
    if (params == null)
        return "";
    StringBuilder sb = new StringBuilder();
    for (Map.Entry<String, String> param : params.entrySet()) {
        sb.append(param.getKey()).append("=").append(param.getValue()).append("&");
    }/*  ww w .  j a v a 2 s .  co m*/
    if (sb.charAt(sb.length() - 1) == '&')
        sb.deleteCharAt(sb.length() - 1);
    return sb.toString();
}

From source file:Main.java

public static String removeFromCollection(String collectionString, String content) {
    String[] elements = collectionString.split(SPLITER);
    StringBuilder builder = new StringBuilder();
    for (String element : elements) {
        if (element.equals(content)) {
            continue;
        }/*from w  ww .j av  a 2s  . c  o  m*/
        builder.append(element).append(",");
    }
    if (builder.length() > 0) {
        builder.deleteCharAt(builder.lastIndexOf(","));
    }
    return builder.toString();
}

From source file:Main.java

public static String stripControlChars(String iString) {
    StringBuilder result = new StringBuilder(iString);
    int idx = result.length();
    while (idx-- > 0) {
        if (result.charAt(idx) < 0x20 && result.charAt(idx) != 0x9 && result.charAt(idx) != 0xA
                && result.charAt(idx) != 0xD)
            result.deleteCharAt(idx);
    }/*w ww.ja  v a2 s. co m*/
    return result.toString();
}