JAVA-MANI.BLOGSPOT.COM
Tuesday, August 26, 2008
This example uses the java.util.regex.Pattern class's split() method to split-up input string separated by commas or whitespaces.

package org.kodejava.example.regex;

import java.util.regex.Pattern;

public class RegexSplitExample {
public static void main(String[] args) {
//
// Pattern for finding commas, whitespaces (space, tabs, new line,
// carriage return, form feed).
//
String pattern = "[,\\s]+";
String colours = "Red,White, Blue Green Yellow, Orange";

Pattern splitter = Pattern.compile(pattern);
String[] result = splitter.split(colours);

for (String colour : result) {
System.out.println("Colour = \"" + colour + "\"");
}
}
}

0 comments:

SUBSCRIBE VIA eMAIL

Enter your email address:

Delivered by FeedBurner

Recent Posts

Firefox 3

Counter

internet companies

Live Traffic Map

Subscribe Now