From 99ce8160513465467e8e7a89242d68d37d019e56 Mon Sep 17 00:00:00 2001 From: hns Date: Mon, 19 May 2003 16:23:42 +0000 Subject: [PATCH] Added StringUtils class for frequently needed string manipulation routine --- src/helma/util/StringUtils.java | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/helma/util/StringUtils.java diff --git a/src/helma/util/StringUtils.java b/src/helma/util/StringUtils.java new file mode 100644 index 00000000..34ddea38 --- /dev/null +++ b/src/helma/util/StringUtils.java @@ -0,0 +1,51 @@ +/* + * Helma License Notice + * + * The contents of this file are subject to the Helma License + * Version 2.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://adele.helma.org/download/helma/license.txt + * + * Copyright 1998-2003 Helma Software. All Rights Reserved. + * + * $RCSfile$ + * $Author$ + * $Revision$ + * $Date$ + */ + +package helma.util; + + +import java.util.StringTokenizer; + +/** + * Utility class for String manipulation. + */ +public class StringUtils { + + + /** + * Split a string into an array of strings. Use comma and space + * as delimiters. + */ + public static String[] split(String str) { + return split(str, ", \t\n\r\f"); + } + + /** + * Split a string into an array of strings. + */ + public static String[] split(String str, String delim) { + if (str == null) { + return new String[0]; + } + StringTokenizer st = new StringTokenizer(str, delim); + String[] s = new String[st.countTokens()]; + for (int i=0; i