Java by API/org.apache.commons.lang/CharSetUtils

Материал из Java эксперт
Версия от 14:47, 31 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

CharSetUtils: count(String str, String set)

/*
B and o count = 3
B,o,k,e and r count = 8 
 */
import org.apache.rumons.lang.CharSetUtils;
public class CharSetUtilsTrial {
  public static void main(String[] args) {
    // Count all occurrences of all the characters specified.
    System.out.println("B and o count = " + CharSetUtils.count("BorisBecker", "Bo")); // 3
    System.out.println("B,o,k,e and r count = "
        + CharSetUtils.count("BorisBecker", new String[] { "Bo", "ker" })); // 8
  }
}





CharSetUtils: count(String str, String[] set) (2)

/*
B and o count = 3
B,o,k,e and r count = 8 
 */
import org.apache.rumons.lang.CharSetUtils;
public class CharSetUtilsTrial {
  public static void main(String[] args) {
    // Count all occurrences of all the characters specified.
    System.out.println("B and o count = " + CharSetUtils.count("BorisBecker", "Bo")); // 3
    System.out.println("B,o,k,e and r count = "
        + CharSetUtils.count("BorisBecker", new String[] { "Bo", "ker" })); // 8
  }
}





CharSetUtils: delete(String str, String set)

/*
Delete B and o = risecker
Delete B,o,k,e and r = isc
 */
import org.apache.rumons.lang.CharSetUtils;
public class CharSetUtilsTrial {
  public static void main(String[] args) {
    // Specified characters deleted.
    System.out.println("Delete B and o = " + CharSetUtils.delete("BorisBecker", "Bo")); // risecker
    System.out.println("Delete B,o,k,e and r = "
        + CharSetUtils.delete("BorisBecker", new String[] { "Bo", "ker" })); // isc
  }
}





CharSetUtils: delete(String str, String[] set) (2)

/*
Delete B and o = risecker
Delete B,o,k,e and r = isc
 */
import org.apache.rumons.lang.CharSetUtils;
public class CharSetUtilsTrial {
  public static void main(String[] args) {
    // Specified characters deleted.
    System.out.println("Delete B and o = " + CharSetUtils.delete("BorisBecker", "Bo")); // risecker
    System.out.println("Delete B,o,k,e and r = "
        + CharSetUtils.delete("BorisBecker", new String[] { "Bo", "ker" })); // isc
  }
}





CharSetUtils: keep(String str, String set)

/*
Keep B and o = BoB
Squeeze B and o = Borisbbbecker
 */
import org.apache.rumons.lang.CharSetUtils;
public class CharSetUtilsTrial {
  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
  }
}





CharSetUtils: squeeze(String str, String set)

/*
Keep B and o = BoB
Squeeze B and o = Borisbbbecker
 */
import org.apache.rumons.lang.CharSetUtils;
public class CharSetUtilsTrial {
  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
  }
}