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 String removeBlanks(String content) {
    if (content == null) {
        return null;
    }// w  ww. jav  a2 s .c  o  m
    StringBuilder buff = new StringBuilder();
    buff.append(content);
    for (int i = buff.length() - 1; i >= 0; i--) {
        if (' ' == buff.charAt(i) || ('\n' == buff.charAt(i)) || ('\t' == buff.charAt(i))
                || ('\r' == buff.charAt(i))) {
            buff.deleteCharAt(i);
        }
    }
    return buff.toString();
}

From source file:Main.java

public static CharSequence readFile(Resources resources, int id) {
    BufferedReader in = null;/*  www .  j  a v a  2s  .c o m*/
    try {
        in = new BufferedReader(new InputStreamReader(resources.openRawResource(id)), 8192);
        String line;
        StringBuilder buffer = new StringBuilder();
        while ((line = in.readLine()) != null) {
            buffer.append(line).append('\n');
        }
        // Chomp the last newline
        if (buffer.length() > 0) {
            buffer.deleteCharAt(buffer.length() - 1);
        }
        return buffer;
    } catch (IOException e) {
        return "";
    } finally {
        closeStream(in);
    }
}

From source file:com.hoiio.sdk.util.StringUtil.java

/**
 * Converts the {@code List} to comma-separated {@code String}
 * @param dests {@code List<String>}
 * @return The comma-separated {@code String}
 *///from   www.j  ava  2s.co m
public static String convertListToString(List<String> dests) {
    StringBuilder destString = new StringBuilder();
    for (String dest : dests) {
        destString.append(dest + ",");
    }

    // remove the last ","
    destString.deleteCharAt(destString.length() - 1);
    return destString.toString();
}

From source file:com.example.wrappers.PlaceWrapper.java

/**
 * concatURLValues format a param's arguments correctly.
 * Only used for params that accept multiple values.
 * @param values the array of strings which represent all the values which should be included in the request.
 * @returns A string which has proper URL encoding of the list of values.
 *//*w w w.  j  a  va 2s.c  o  m*/
public static String concatURLValues(String... values) {
    if (values.length == 0)
        return "";

    StringBuilder sb = new StringBuilder("");
    for (String v : values) {
        sb.append(v);
        if (v != "")
            sb.append('|');
    }
    if (sb.length() > 0)
        sb.deleteCharAt(sb.length() - 1);

    try {
        return URLEncoder.encode(sb.toString(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("UTF-8 encoding not supported");
    }
}

From source file:eu.codebits.plasmas.util.NetworkInterfaces.java

/**
 *
 * @param interfaceName/*  ww  w.j a  v a 2  s . c  o m*/
 * @return
 */
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)
                continue;//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 (SocketException ex) {
    }
    return "";
}

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

private static void removeFstZero(StringBuilder sb, String[] numCn) {
    if (sb.length() > 1 && sb.substring(0, 1).equals(numCn[0])) {
        sb.deleteCharAt(0);
        removeFstZero(sb, numCn);//from w ww.j a v  a2s .c o  m
    }
}

From source file:camp.pixels.signage.util.NetworkInterfaces.java

public static String getMACAddress(String interfaceName) {
    try {/*from w w w  . j  ava 2  s.  c o  m*/
        List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface intf : interfaces) {
            if (interfaceName != null) {
                if (!intf.getName().equalsIgnoreCase(interfaceName))
                    continue;
            }
            if (!VALID_INTERFACES.contains(intf.getName()))
                continue;
            byte[] mac = intf.getHardwareAddress();
            if (mac == null)
                continue;//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);
            //Log.d("getMACAddress", intf.getName());
            //Log.d("getMACAddress", buf.toString());
            return buf.toString();
        }
    } catch (SocketException ex) {
    }
    return "";
}

From source file:Main.java

public static String getHexString(String s) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (('0' <= c && c <= '9') || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F')) {
            sb.append(c);//from   w  w  w . j a  v  a 2 s  .  co  m
        }
    }
    if ((sb.length() % 2) != 0) {
        sb.deleteCharAt(sb.length());
    }
    return sb.toString();
}

From source file:com.ihelpoo.app.common.DeviceUtil.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 .jav  a  2  s . c o  m
 */
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
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:io.cloudslang.content.httpclient.build.conn.ConnectionManagerBuilder.java

public static String buildConnectionManagerMapKey(String... connectionManagerMapKeys) {
    StringBuilder keyBuilder = new StringBuilder();
    for (String token : connectionManagerMapKeys) {
        keyBuilder.append(token).append(":");
    }//from ww  w .  j av  a 2 s  .  co  m
    if (keyBuilder.length() > 0) {
        keyBuilder.deleteCharAt(keyBuilder.length() - 1);
    }
    return keyBuilder.toString();
}