Example usage for java.lang String subSequence

List of usage examples for java.lang String subSequence

Introduction

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

Prototype

public CharSequence subSequence(int beginIndex, int endIndex) 

Source Link

Document

Returns a character sequence that is a subsequence of this sequence.

Usage

From source file:Main.java

public static String processAsteriskLabel(String labelString) {

    if (labelString == null) {

        return null;

    }/*from  w w w.  j a v a  2  s.co m*/

    StringBuffer sb = new StringBuffer("");

    sb.append("<html><body>&nbsp;");

    int index = labelString.lastIndexOf("*");

    if (index > -1) {

        sb.append(labelString.subSequence(0, index));

        sb.append("<font color='red'>*</font>");

    } else {

        sb.append(labelString + "&nbsp;");

    }

    sb.append("</body></html>");

    return sb.toString();

}

From source file:com.ms.commons.test.treedb.JsonObjectUtils.java

private static String calExclusive(List<Node> list, String jsons) {
    StringBuilder sb = new StringBuilder();
    int start = 0;
    for (Node p : list) {
        sb.append(jsons.subSequence(start, p.kvStart));
        start = p.kvEnd + 1;//from w w  w .j  av  a  2 s  . c o m
    }
    sb.append(jsons.subSequence(start, jsons.length()));
    return sb.toString();
}

From source file:StringUtil.java

/**
 * Center the contents of the string. If the supplied string is longer than the desired width, it is truncated to the
 * specified length. If the supplied string is shorter than the desired width, padding characters are added to the beginning
 * and end of the string such that the length is that specified; one additional padding character is prepended if required.
 * All leading and trailing whitespace is removed before centering.
 * // w  ww  .j a  v  a  2 s  . co  m
 * @param str the string to be left justified; if null, an empty string is used
 * @param width the desired width of the string; must be positive
 * @param padWithChar the character to use for padding, if needed
 * @return the left justified string
 * @see #setLength(String, int, char)
 */
public static String justifyCenter(String str, final int width, char padWithChar) {
    // Trim the leading and trailing whitespace ...
    str = str != null ? str.trim() : "";

    int addChars = width - str.length();
    if (addChars < 0) {
        // truncate
        return str.subSequence(0, width).toString();
    }
    // Write the content ...
    int prependNumber = addChars / 2;
    int appendNumber = prependNumber;
    if ((prependNumber + appendNumber) != addChars) {
        ++prependNumber;
    }

    final StringBuilder sb = new StringBuilder();

    // Prepend the pad character(s) ...
    while (prependNumber > 0) {
        sb.append(padWithChar);
        --prependNumber;
    }

    // Add the actual content
    sb.append(str);

    // Append the pad character(s) ...
    while (appendNumber > 0) {
        sb.append(padWithChar);
        --appendNumber;
    }

    return sb.toString();
}

From source file:StringUtil.java

protected static String justifyLeft(String str, final int width, char padWithChar, boolean trimWhitespace) {
    // Trim the leading and trailing whitespace ...
    str = str != null ? (trimWhitespace ? str.trim() : str) : "";

    int addChars = width - str.length();
    if (addChars < 0) {
        // truncate
        return str.subSequence(0, width).toString();
    }/*from   ww w . j a  v  a 2 s. c  o m*/
    // Write the content ...
    final StringBuilder sb = new StringBuilder();
    sb.append(str);

    // Append the whitespace ...
    while (addChars > 0) {
        sb.append(padWithChar);
        --addChars;
    }

    return sb.toString();
}

From source file:Main.java

/**
 * @brief      get charset value from one full html buffer
 * /*ww w .  ja v a  2 s  .co m*/
 * @param      buffer   [IN]  html buffer
 * 
 * @return     Return charset value
 */
public static String getCharSet(byte[] buffer) {
    final int MAX_HEADER_LENGTH = 512;
    String tmpStr = new String(buffer, 0, MAX_HEADER_LENGTH);
    boolean bHasCharSet = false;
    if (tmpStr.contains("charset")) {
        int start = tmpStr.indexOf("charset");
        int end1 = tmpStr.indexOf(";", start);
        int end2 = tmpStr.indexOf("\"", start);
        int end = end1 < end2 && end1 != -1 ? end1 : end2;
        tmpStr = (String) tmpStr.subSequence(start + 7, end);
        tmpStr = tmpStr.replace("=", "");
        tmpStr = tmpStr.trim();
        bHasCharSet = true;
    }

    if (!bHasCharSet) {
        tmpStr = "utf-8";
    }
    return tmpStr;
}

From source file:de.iteratec.iteraplan.presentation.dialog.GraphicalReporting.Line.JFreeChartSvgRenderer.java

private static byte[] addAdditionalAttributes(byte[] originalSvgXml) {
    //Implemented using basic string manipulation for enhanced performance
    try {//  w w  w.j a v  a 2s  . c o  m
        String xml = new String(originalSvgXml, "UTF-8");
        int svgStartIndex = xml.indexOf("<svg");
        int svgEndIndex = xml.indexOf('>', svgStartIndex);
        StringBuilder sb = new StringBuilder();
        sb.append(xml.subSequence(0, svgEndIndex));
        sb.append(" viewBox=\"0 0 " + JFreeChartLineGraphicCreator.DEFAULT_WIDTH + " "
                + JFreeChartLineGraphicCreator.DEFAULT_HEIGHT + "\"");
        sb.append(xml.substring(svgEndIndex));

        return sb.toString().getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new IteraplanTechnicalException(e);
    }
}

From source file:StringUtil.java

/**
 * Right justify the contents of the string, ensuring that the string ends at the last character. If the supplied string is
 * longer than the desired width, the leading characters are removed so that the last character in the supplied string at the
 * last position. If the supplied string is shorter than the desired width, the padding character is inserted one or more
 * times such that the last character in the supplied string appears as the last character in the resulting string and that
 * the length matches that specified./*from ww  w.  j a  va 2  s  .com*/
 * 
 * @param str the string to be right justified; if null, an empty string is used
 * @param width the desired width of the string; must be positive
 * @param padWithChar the character to use for padding, if needed
 * @return the right justified string
 */
public static String justifyRight(String str, final int width, char padWithChar) {
    assert width > 0;
    // Trim the leading and trailing whitespace ...
    str = str != null ? str.trim() : "";

    final int length = str.length();
    int addChars = width - length;
    if (addChars < 0) {
        // truncate the first characters, keep the last
        return str.subSequence(length - width, length).toString();
    }
    // Prepend the whitespace ...
    final StringBuilder sb = new StringBuilder();
    while (addChars > 0) {
        sb.append(padWithChar);
        --addChars;
    }

    // Write the content ...
    sb.append(str);
    return sb.toString();
}

From source file:com.bearstech.android.myownsync.client.NetworkUtilities.java

public static void setBaseURL(String uri) {
    if (!uri.startsWith("http://"))
        uri = "http://" + uri;
    if (uri.endsWith("/"))
        uri.subSequence(0, uri.length() - 1);
    base_url = uri;/*from w  w  w . j  av a 2 s  .  c o m*/
}

From source file:com.nextgis.mobile.map.LocalGeoJsonLayer.java

public static void create(final MapBase map, Uri uri) {
    String sName = getFileNameByUri(map.getContext(), uri, "new layer.geojson");
    sName = (String) sName.subSequence(0, sName.length() - 8);
    showPropertiesDialog(map, true, sName, uri, null);
}

From source file:com.eryansky.common.utils.io.FileUtil.java

/**
 * ?//from w  w w . j  a v  a2  s  . c om
 * 
 * @param src
 *            ?
 * @param dst
 *            
 */
public static void copyFile(File src, File dst) {
    try {
        FileInputStream in = null;
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(dst);
            in = new FileInputStream(src);
            byte[] buffer = new byte[1024];
            int len = 0;
            while ((len = in.read(buffer)) > 0) {
                out.write(buffer, 0, len);
            }
        } catch (Exception e) {
            e.printStackTrace();
            String dstpath = dst.getAbsolutePath();
            if (dstpath.lastIndexOf("/") != -1) {
                dstpath = dstpath.subSequence(0, dstpath.lastIndexOf("/")).toString();
            } else {
                dstpath = dstpath.subSequence(0, dstpath.lastIndexOf("\\")).toString();
            }
            createDirectory(dstpath);
            copyFile(src, dst);
        } finally {
            if (null != in) {
                in.close();
            }
            if (null != out) {
                out.close();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}