List of usage examples for org.apache.commons.lang CharSetUtils squeeze
public static String squeeze(String str, String[] set)
Squeezes any repetitions of a character that is mentioned in the supplied set.
An example is:
From source file:MainClass.java
public static void main(String[] args) { //Removes specified character repetitions System.out.println("Squeeze B and o = " + CharSetUtils.squeeze("BBoooorisbbbecker", "Bo")); }
From source file:CharSetUtilsTrial.java
public static void main(String[] args) { // Keeps only the characters specified System.out.println("Keep B and o = " + CharSetUtils.keep("BorisBecker", "Bo")); // BoB // Removes specified character repetitions System.out.println("Squeeze B and o = " + CharSetUtils.squeeze("BBoooorisbbbecker", "Bo")); // Borisbbbecker }
From source file:org.apache.wookie.w3c.util.UnicodeUtils.java
/** * Normalizes all space characters (and whitespace if includeWhitespace is set to true) in the given string to * U+0020, then collapses multiple adjacent spaces to a single space, and * removes any leading and trailing spaces. If the input string is null, * the method returns an empty string ("") * @param in the string to normalize//w ww . j av a2s. c om * @param includeWhitespace set to true to normalize whitespace as well as space characters * @return the normalized string */ private static String normalize(String in, boolean includeWhitespace) { if (in == null) return ""; // Create a buffer for the string StringBuffer buf = new StringBuffer(); // Iterate over characters in the string and append them to buffer, replacing matching characters with standard spaces for (int x = 0; x < in.length(); x++) { char ch = in.charAt(x); if (Character.isSpaceChar(ch) || (Character.isWhitespace(ch) && includeWhitespace)) { ch = ' '; } buf.append(ch); } String str = buf.toString(); // Squeeze out extra spaces str = CharSetUtils.squeeze(str, " "); // Strip off trailing and leading spaces str = StringUtils.strip(str); return str; }
From source file:org.rascalmpl.library.Prelude.java
public IString squeeze(IString src, IString charSet) { //@{http://commons.apache.org/lang/api-2.6/index.html?org/apache/commons/lang/text/package-summary.html} String s = CharSetUtils.squeeze(src.getValue(), charSet.getValue()); return values.string(s); }