我想解析一个包含情感符号的字符串,比如":)",":p","!","?"
单词。例如,像这个字符串"How dare you! You have lost him two days ago:'("
,我想得到这样的结果:
How
dare
you
!
You
have
lost
him
two
days
ago
:'(
我StringTokenizer
习惯用分隔符解析句子,但我失去了情感符号。谢谢
我使用的代码:
public class FullParser {
private String sentence;
private String separator="' ,.:!()@/<>";
private ArrayList<String> mywords;
public FullParser(String sentence){
this.sentence=sentence;
mywords=new ArrayList<String>();
separator+='"';
}
public void parsing(){
StringTokenizer st = new StringTokenizer( sentence, separator, true );
while ( st.hasMoreTokens() ) {
String token = st.nextToken();
if (!( token.length() == 1 && separator.indexOf( token.charAt( 0 ) ) >= 0 )) {
//Log.i("PARSER",token);
mywords.add(token);
}
}
}
public ArrayList<String> getmyWords(){
return mywords;
}