単語などの感情的な表記を含む文字列を解析したい":)",":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;
}