Example usage for java.lang StringBuilder delete

List of usage examples for java.lang StringBuilder delete

Introduction

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

Prototype

@Override
public StringBuilder delete(int start, int end) 

Source Link

Usage

From source file:Main.java

private static List<String> allTransactions(String pdfTextForm) {
    String[] lines = pdfTextForm.split("\n"); //New line splitter
    int transactionNumber = 1;
    StringBuilder onetransactionStr = new StringBuilder();
    boolean isTransactionFound = false;
    List<String> allTransaction = new ArrayList<>();
    for (String l : lines) {
        // System.out.println("current line :" + l);
        if (l.trim().equals(transactionNumber + "")) {
            isTransactionFound = true;/*  ww w.  ja v a2  s.  co  m*/
            onetransactionStr.append(l).append(" ");
        } else if (l.trim().equals((transactionNumber + 1 + ""))) {
            transactionNumber++;
            allTransaction.add(onetransactionStr.toString());
            onetransactionStr.delete(0, onetransactionStr.length());
            onetransactionStr.append(l).append(" ");
        } else if (l.contains("Opening balance") || l.contains("Closing balance")) // End of all transactions
        {
            allTransaction.add(onetransactionStr.toString());
            break;
        } else if (isTransactionFound) {
            onetransactionStr.append(l).append(" ");
        }
    }

    return allTransaction;
}

From source file:spring.osgi.utils.OsgiHeaderUtils.java

private static String[] getHeaderWithAttributesAsTrimmedStringArray(Bundle bundle, String header) {
    if (bundle == null || !StringUtils.hasText(header))
        return new String[0];

    String headerContent = bundle.getHeaders().get(header);

    if (!StringUtils.hasText(headerContent))
        return new String[0];

    // consider , as a delimiter only if a quote is not encountered
    List<String> tokens = new ArrayList<>(2);

    StringBuilder token = new StringBuilder();
    boolean ignoreComma = false;
    for (int stringIndex = 0; stringIndex < headerContent.length(); stringIndex++) {
        char currentChar = headerContent.charAt(stringIndex);
        if (currentChar == COMMA_CHAR) {
            if (ignoreComma) {
                token.append(currentChar);
            } else {
                tokens.add(token.toString().trim());
                token.delete(0, token.length());
                ignoreComma = false;/*from   w w  w.  j av a 2  s .com*/
            }
        } else {
            if (currentChar == QUOTE_CHAR) {
                ignoreComma = !ignoreComma;
            }
            token.append(currentChar);
        }
    }
    tokens.add(token.toString().trim());
    return tokens.toArray(new String[tokens.size()]);
}

From source file:Main.java

private static StringBuilder replaceString(StringBuilder text, String search, String replace) {
    int fromIndex = 0;

    int start = text.indexOf(search, fromIndex);
    if (start == -1) {
        return text;
    }// w  w w .j  a  v a2 s .c  om

    if (replace.length() > 0) {
        int end = 0;

        int endAdjust = (search.length() - replace.length());
        do {
            end = (start + replace.length()) + endAdjust;
            text.replace(start, end, replace);
            fromIndex = end;
        } while ((start = text.indexOf(search, fromIndex)) != -1);
    } else {
        do {
            text.delete(start, search.length());
            fromIndex = start + replace.length();
        } while ((start = text.indexOf(search, fromIndex)) != -1);
    }

    return text;
}

From source file:Main.java

public static String borraEtiqueta(String tag, String contenido, String documento) {
    StringBuilder st = new StringBuilder(documento);
    int posBusquedaInicio = 0;
    int tamanioDocumento = st.length();
    while (posBusquedaInicio < tamanioDocumento) {
        int posInicio = st.indexOf("<" + tag + ">", posBusquedaInicio);
        if (posInicio != -1) {
            String t = "</" + tag + ">";
            int posFin = st.indexOf(t, posBusquedaInicio);
            int longitudTag = t.length();
            int posContenido = documento.indexOf(contenido);
            if (posInicio < posContenido && posContenido < posFin) {
                st.delete(posInicio, posFin + longitudTag);
                return st.toString();
            }/*from w w  w  . j ava 2  s. co  m*/
            posBusquedaInicio = posFin + longitudTag;

        } else {
            return documento;
        }

    }
    return documento;
}

From source file:net.firejack.platform.core.utils.StringUtils.java

/**
 * @param text/*from ww  w  .  jav a  2s.  c  om*/
 * @param len
 * @return
 */
public static String[] wrapText(String text, int len) {
    // return empty array for null text
    if (text == null)
        return new String[] {};

    // return text if len is zero or less
    if (len <= 0)
        return new String[] { text };

    // return text if less than length
    if (text.length() <= len)
        return new String[] { text };

    char[] chars = text.toCharArray();
    Vector lines = new Vector();
    StringBuilder line = new StringBuilder();
    StringBuilder word = new StringBuilder();

    for (char aChar : chars) {
        word.append(aChar);

        if (aChar == ' ') {
            if ((line.length() + word.length()) > len) {
                lines.add(line.toString());
                line.delete(0, line.length());
            }

            line.append(word);
            word.delete(0, word.length());
        }
    }

    // handle any extra chars in current word
    if (word.length() > 0) {
        if ((line.length() + word.length()) > len) {
            lines.add(line.toString());
            line.delete(0, line.length());
        }
        line.append(word);
    }

    // handle extra line
    if (line.length() > 0) {
        lines.add(line.toString());
    }

    String[] ret = new String[lines.size()];
    int c = 0; // counter
    for (Enumeration e = lines.elements(); e.hasMoreElements(); c++) {
        ret[c] = (String) e.nextElement();
    }

    return ret;
}

From source file:com.github.gekoh.yagen.hibernate.PatchHibernateMappingClasses.java

public static SqlStatement prepareDDL(String sql) {
    sql = sql.trim();/*from   w w  w .j  a v a  2s  .  c  om*/
    String delimiter = "";

    Matcher matcher = PLSQL_END_PATTERN.matcher(sql);
    if (matcher.find()) {
        if (matcher.group(2) != null) {
            sql = sql.substring(0, matcher.start(2));
        }
        sql += "\n";
        delimiter = "/";
    }
    // remove trailing semicolon in case of non pl/sql type objects/statements
    else if (sql.endsWith(";")) {
        sql = sql.substring(0, sql.length() - 1);
    }

    StringBuilder sqlWoComments = new StringBuilder(sql);
    while ((matcher = COMMENT_PATTERN.matcher(sqlWoComments.toString())).find()) {
        sqlWoComments.delete(matcher.start(), matcher.end());
    }

    if (delimiter.length() < 1 && sqlWoComments.toString().trim().length() > 0) {
        delimiter = ";";
    }

    return new SqlStatementImpl(sql, delimiter);
}

From source file:com.example.mobilewebproxy.MainActivity.java

private static String getBytesTextValue(String prevCount, long countRaise) {

    long totalBytes = countRaise;
    Double prevNum;//from  w  ww  .  j a v a2  s  .  com
    Double convertedValue;
    StringBuilder builder = new StringBuilder(prevCount);

    if (!prevCount.endsWith("kb") && !prevCount.endsWith("mb")) {
        builder.deleteCharAt(prevCount.length() - 1);

        Integer temp = Integer.parseInt(builder.toString());
        totalBytes += temp.longValue();
    } else if (prevCount.endsWith("kb")) {
        builder.delete(prevCount.length() - 2, prevCount.length());

        prevNum = Double.parseDouble(builder.toString());
        convertedValue = prevNum * 1024.0;

        totalBytes += convertedValue.longValue();
    }

    else if (prevCount.endsWith("mb")) {
        builder.delete(prevCount.length() - 2, prevCount.length());

        prevNum = Double.parseDouble(builder.toString());
        convertedValue = prevNum * 1024.0 * 1024.0;

        totalBytes += convertedValue.longValue();
    }

    return bytesToReadableString(totalBytes);
}

From source file:edu.mit.csail.sdg.alloy4.Terminal.java

private static String getAvaliableSatSolvers() {
    StringBuilder sb = new StringBuilder();
    for (Field f : A4Options.SatSolver.class.getFields()) {
        if (A4Options.SatSolver.class.isAssignableFrom(f.getType())) {
            sb.append(f.getName() + ", ");
        }/*from  ww  w .  j  a v a 2 s . co m*/
    }
    if (sb.length() > 2) {
        sb.delete(sb.length() - 2, sb.length());
    }
    return sb.toString();
}

From source file:Main.java

private static String removeDotSegments(StringBuilder uri, int offset, int limit) {
    if (offset >= limit) {
        return uri.toString();
    }//  w w w. j a  v a 2s .  co  m
    if (uri.charAt(offset) == '/') {
        offset++;
    }

    int segmentStart = offset;
    int i = offset;
    while (i <= limit) {
        int nextSegmentStart;
        if (i == limit) {
            nextSegmentStart = i;
        } else if (uri.charAt(i) == '/') {
            nextSegmentStart = i + 1;
        } else {
            i++;
            continue;
        }

        if (i == segmentStart + 1 && uri.charAt(segmentStart) == '.') {
            uri.delete(segmentStart, nextSegmentStart);
            limit -= nextSegmentStart - segmentStart;
            i = segmentStart;
        } else if (i == segmentStart + 2 && uri.charAt(segmentStart) == '.'
                && uri.charAt(segmentStart + 1) == '.') {
            int prevSegmentStart = uri.lastIndexOf("/", segmentStart - 2) + 2;
            int removeFrom = prevSegmentStart > offset ? prevSegmentStart : offset;
            uri.delete(removeFrom, nextSegmentStart);
            limit -= nextSegmentStart - removeFrom;
            i = prevSegmentStart;
        } else {
            i++;
            segmentStart = i;
        }
    }
    return uri.toString();
}

From source file:com.uber.hoodie.hive.client.SchemaUtil.java

public static String generateSchemaString(MessageType storageSchema) throws IOException {
    Map<String, String> hiveSchema = convertParquetSchemaToHiveSchema(storageSchema);
    StringBuilder columns = new StringBuilder();
    for (Map.Entry<String, String> hiveSchemaEntry : hiveSchema.entrySet()) {
        columns.append(hiveSchemaEntry.getKey()).append(" ");
        columns.append(hiveSchemaEntry.getValue()).append(", ");
    }/*  ww w. j  a  v  a2s  .com*/
    // Remove the last ", "
    columns.delete(columns.length() - 2, columns.length());
    return columns.toString();
}