Java by API/org.apache.commons.lang/CharSetUtils — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 17:47, 31 мая 2010
Содержание
CharSetUtils: count(String str, String set)
<source lang="java">
/* 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 }
}
</source>
CharSetUtils: count(String str, String[] set) (2)
<source lang="java">
/* 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 }
}
</source>
CharSetUtils: delete(String str, String set)
<source lang="java">
/* 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 }
}
</source>
CharSetUtils: delete(String str, String[] set) (2)
<source lang="java">
/* 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 }
}
</source>
CharSetUtils: keep(String str, String set)
<source lang="java">
/* 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 }
}
</source>
CharSetUtils: squeeze(String str, String set)
<source lang="java">
/* 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 }
}
</source>