Java String Collapse collapseString(String data, String collapse)

Here you can find the source of collapseString(String data, String collapse)

Description

Collapse a String from an input String.

License

Apache License

Parameter

Parameter Description
data the input String
collapse the data to collapse from the string.

Return

String

Declaration

public static final String collapseString(String data, String collapse) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//w  w w . ja  va  2 s .c o m
     * Collapse a String from an input String.
     * @param data the input String
     * @param collapse the data to collapse from the string.
     * @return String
     */
    public static final String collapseString(String data, String collapse) {
        if (data == null || collapse == null)
            return null;

        StringBuffer t1;

        int pos = data.indexOf(collapse);
        if (pos == -1)
            return data;

        t1 = new StringBuffer();
        int start = 0;
        while (pos != -1) {
            t1.append(data.substring(start, pos));
            start = pos + collapse.length();
            pos = data.indexOf(collapse, start);
        }
        t1.append(data.substring(start));
        return t1.toString();
    }
}

Related

  1. collapsedName(Class klass)
  2. collapseLines(String message)
  3. collapseMultipleNewlinesToOne(String s)
  4. collapseName(String name)
  5. collapseNewlines(String argStr)
  6. collapseStrings(String[] strings)