JAVA 正则表达式的应用——split按自己所设定的字符分割
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String args[]) throws IOException{ BufferedReader cin = new BufferedReader(new InputStreamReader(System.in)); Scanner scan = new Scanner(System.in); int T = 0; T = scan.nextInt(); while (T != 0) { String s = cin.readLine(); System.out.println("T = " + T); // String tm[] = s.split("\\s+");//以空格分割,中间可以出现多个空格 // String tm[] = s.split("\\d+");//一人一数字分割中间所有数字都会省略 String tm[] = s.split("\\*+"); for (int i = 0; i < tm.length; ++i) { System.out.println(tm[i]); } T--; } } }
http://developer.51cto.com/art/200902/110238.htm