Example usage for java.lang StringBuffer toString

List of usage examples for java.lang StringBuffer toString

Introduction

In this page you can find the example usage for java.lang StringBuffer toString.

Prototype

@Override
    @HotSpotIntrinsicCandidate
    public synchronized String toString() 

Source Link

Usage

From source file:Main.java

public static String replaceCharAt(String s, int pos, char c) {
    StringBuffer buf = new StringBuffer(s);
    buf.setCharAt(pos, c);//from   ww  w . j a  v a 2  s  .  c o m
    return buf.toString();
}

From source file:Main.java

public static String findTag(String tagName, StringBuffer result) {
    String search = result.toString();
    String startTag = "<" + tagName + ">";
    String endTag = "</" + tagName + ">";
    int start = search.indexOf(startTag);
    int end = search.indexOf(endTag);

    if (start == -1 || end == -1) {
        return null;
    }//from ww w .jav a2  s.co m

    String val = search.substring(start + startTag.length(), end);
    result.delete(0, end + endTag.length());
    return val;
}

From source file:Main.java

/**
 * Because GCJ/GIJ Classpath doesn't support StringBuffer.indexOf, we have
 * to have a replacement that uses Strings instead.
 * @param buffer The StringBuffer to find in
 * @param string The String to find/*ww  w  .j a  va  2s. c  o  m*/
 * @return The index of the string or -1 if it wasn't found
 */
public static int getStringBufferIndexOf(StringBuffer buffer, String string) {
    return buffer.toString().indexOf(string);
}

From source file:Main.java

public static String findAttributeValue(String tagName, String attrName, StringBuffer result) {
    String search = result.toString();
    String startTag = "<" + tagName + " " + attrName + "='";
    String endTag = "'/>";
    int start = search.indexOf(startTag);
    int end = -1;
    if (start != -1) {
        end = search.indexOf(endTag, start);
    }//from  ww  w . j a va 2  s . c o  m

    if (start == -1 || end == -1 || end < start) {
        return "unk";
    }

    String val = search.substring(start + startTag.length(), end);
    result.delete(0, end + endTag.length() - 1);
    return val;
}

From source file:Main.java

public static String subTel(String number) {
    if (number != null && number.length() == 11) {
        StringBuffer buffer = new StringBuffer(number);
        StringBuffer replace = buffer.replace(3, 7, "****");
        return replace.toString();
    }/*from ww w  .j a v  a  2s  .  c  o  m*/
    return null;
}

From source file:Main.java

/**
 * Because GCJ/GIJ Classpath doesn't support StringBuffer.indexOf, we have
 * to have a replacement that uses Strings instead.
 * @param buffer The StringBuffer to find in
 * @param string The String to find/*from   ww w . j  a  v  a 2 s. c  o m*/
 * @param fromIndex The char index to search from
 * @return The index of the string or -1 if it wasn't found
 */
public static int getStringBufferIndexOf(StringBuffer buffer, String string, int fromIndex) {
    return buffer.toString().indexOf(string, fromIndex);
}

From source file:Main.java

/**
 * MMdd -> MM-dd/*from  www.ja  v  a  2 s  .  c o m*/
 * 
 * @param MMdd
 * @return
 */
public static String formatMMddDash(String MMdd) {
    if (null != MMdd && MMdd.length() == 4) {
        StringBuffer sb = new StringBuffer(MMdd);
        sb.insert(2, "-");
        return sb.toString();

    }
    return MMdd;
}

From source file:Main.java

/**
 * Invokes append tail on matcher with the given string buffer, and returns
 * the string buffer as a string./*from   www .  j  a v  a  2  s  .  co  m*/
 *
 * @param matcher the matcher.
 * @param sb      the string buffer.
 * @return a string.
 */
public static String appendTail(Matcher matcher, StringBuffer sb) {
    matcher.appendTail(sb);
    return sb.toString();
}

From source file:Main.java

public static String getAttAsString(String name, String val) {

    StringBuffer sb = new StringBuffer();
    sb.append(" " + name + "=\"" + val + "\"");

    return sb.toString();
}

From source file:Main.java

public static String getAttAsString(final String name, final String val) {

    StringBuffer sb = new StringBuffer();
    sb.append(" " + name + "=\"" + val + "\"");

    return sb.toString();
}