Code example for StringTokenizer

Methods: countTokens, nextToken

0
	 * @return 
	 * @throws I2B2Exception 
	 */ 
	public static String buildBetweenClause(String betweenConstraint)
			throws I2B2Exception { 
		StringTokenizer st = new StringTokenizer(betweenConstraint);
		String firstElement = "", andElement = "", thirdElement = "";
		if (st.countTokens() == 3) {
			firstElement = st.nextToken();
			andElement = st.nextToken();
			thirdElement = st.nextToken();
			if (!andElement.equalsIgnoreCase("and")) {
				throw new I2B2Exception("Invalid between clause [" 
						+ betweenConstraint + "]");
			} 
		} else { 
			throw new I2B2Exception("Invalid between clause [" 
					+ betweenConstraint + "]");
		} 
		return firstElement.replaceAll("'", "''") + " and "
				+ thirdElement.replaceAll("'", "''");