List of usage examples for org.apache.commons.lang CharSetUtils count
public static int count(String str, String[] set)
Takes an argument in set-syntax, see evaluateSet, and returns the number of characters present in the specified string.
An example would be:
From source file:MainClass.java
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")); System.out.println(//from w w w . ja v a 2 s . co m "B,o,k,e and r count = " + CharSetUtils.count("BorisBecker", new String[] { "Bo", "ker" })); }
From source file:CharSetUtilsTrial.java
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(//ww w .j av a 2s . c o m "B,o,k,e and r count = " + CharSetUtils.count("BorisBecker", new String[] { "Bo", "ker" })); // 8 }
From source file:com.silverwrist.dynamo.xmlrpc.Validator1Suite.java
/** * <CODE>validator1.countTheEntities(string) returns struct</CODE><P> *///from www . ja va2 s. c om private Map countTheEntities(Request r) throws FaultCode { Map pm = r.getParameters(); if (pm.size() != 1) throw new XmlRpcParameterError("validator1.countTheEntities: wrong parameter count"); Object foo = pm.get("0"); if (!(foo instanceof String)) throw new XmlRpcParameterError("validator1.countTheEntities: string expected"); String s = (String) foo; // Create the output value. HashMap rc = new HashMap(); rc.put("ctLeftAngleBrackets", new Integer(CharSetUtils.count(s, "<"))); rc.put("ctRightAngleBrackets", new Integer(CharSetUtils.count(s, ">"))); rc.put("ctAmpersands", new Integer(CharSetUtils.count(s, "&"))); rc.put("ctApostrophes", new Integer(CharSetUtils.count(s, "'"))); rc.put("ctQuotes", new Integer(CharSetUtils.count(s, "\""))); return rc; }