Java String Collapse collapseMultipleNewlinesToOne(String s)

Here you can find the source of collapseMultipleNewlinesToOne(String s)

Description

collapse Multiple Newlines To One

License

Open Source License

Declaration

public static String collapseMultipleNewlinesToOne(String s) 

Method Source Code

//package com.java2s;

public class Main {
    public static String collapseMultipleNewlinesToOne(String s) {
        return s.replaceAll("\\\n+", "\\\n");
    }//from  w  w  w  . j  a v  a 2 s .com

    public static String replaceAll(String sSource, String sPattern, String sReplacement) {
        if (sSource == null || sSource.equals("")) {
            return sSource;
        }

        String sResult = new String(sSource);

        int i = sResult.indexOf(sPattern);
        while (i != -1) {
            String sFront = sResult.substring(0, i);
            String sBack = sResult.substring(i + sPattern.length());

            sResult = sFront + sReplacement + sBack;

            i = sResult.indexOf(sPattern);
        }

        return sResult;
    }
}

Related

  1. collapse(String str, String characters, String replacement)
  2. collapse(String t)
  3. collapse(String text)
  4. collapsedName(Class klass)
  5. collapseLines(String message)
  6. collapseName(String name)
  7. collapseNewlines(String argStr)
  8. collapseString(String data, String collapse)
  9. collapseStrings(String[] strings)