晕!你用下IO中的一个类PushbackReader。然后把文本框中的字符做流进去。只要遇到一个","符号就把计数器+1。然后用for循环生成按扭。
不知道行不行。
import java.io.IOException;
import java.io.PushbackReader;
import java.io.StringReader;
public class Pushback {
public static void main(String[] args) {
String str = "liuwei19810609";
try {
PushbackReader in = new PushbackReader(new StringReader(str));
int c = 0;
c = in.read();
String temp = "" + (char) c;
boolean f = Character.isDigit((char) c) ? true : false;
while ((c = in.read()) != -1) {
if (f ^ Character.isDigit((char) c)) {
in.unread(c);
f = !f;
System.out.println(temp);
temp = "";
} else {
temp += (char) c;
}
}
System.out.println(temp);
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
}
}希望给你带来点启示!
不知道行不行。
import java.io.IOException;
import java.io.PushbackReader;
import java.io.StringReader;
public class Pushback {
public static void main(String[] args) {
String str = "liuwei19810609";
try {
PushbackReader in = new PushbackReader(new StringReader(str));
int c = 0;
c = in.read();
String temp = "" + (char) c;
boolean f = Character.isDigit((char) c) ? true : false;
while ((c = in.read()) != -1) {
if (f ^ Character.isDigit((char) c)) {
in.unread(c);
f = !f;
System.out.println(temp);
temp = "";
} else {
temp += (char) c;
}
}
System.out.println(temp);
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
}
}希望给你带来点启示!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货