Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Splitting Strings into Strings[] in java 1.3

807569Aug 1 2006 — edited Aug 1 2006
I found a way to easily split strings using java 1.3 that I haven't seen before, and it doesn't involve StringTokenizer.

First, download the 1.4.2 api and extract ASCII.java, Matcher.java, and Pattern.java from src.zip. Next, change the package to whatever you want and then compile them. After that, just make a StringSplit class that looks something like:
public class StringSplit {
	public static String[] split(String str, String regex)
	{
		return Pattern.compile(regex).split(str, 0);
	}
}
This works a lot nicer than the StringTokenizer method in many circumstances.

Just thought I'd share that
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 29 2006
Added on Aug 1 2006
9 comments
246 views