1

単語のリストがあり、トークン化した後、リストに実際には不要な空のスペースがいくつかあります。提案してください...

サンプル文字列

String str = "3) type an \"l\" in the search field (\"bl\")"+
"4) startHistorySearch()'s previous result contains [\"blah\", \"baaa\", \"bloop\", \"bzzz\"], Satchel filters this down to [\"blah\", \"bloop\"] to match the new \"bl\" search string"+
and so on.....

ここにコードと出力スニペットがあります

String[] splitString = (EXAMPLE_TEST.split("[\\[\\],\\'\"  \\(\\)\\{\\}\\*\\.]"));

出力

nsIAutoCompletResult, , no, , Simple, , , , so, the, QI, fails, , historyResult

そして、いくつかの場所で私はこのように見ます...

finds, 1, entry, , , blah, , , , search-suggestions, finds, , baaa, , , , bloop, , , , bzzz, , , the, autocompete, menu, shows, these, in, order, with, a, divider, between, , blah, , and, , baaa, , 3, , type, , l, , in, the, search, field, , , bl, , 4, , startHistorySearch, , , s, previous, result, contains, , , blah, , , , baaa, , , , bloop, , , , bzzz, , , , Satchel, filters, this, down, to, , , blah, , , , bloop, , , to, match, the, new, , bl, , search, string5, , nsSearchSuggestions, s, onReadyState, , , change, is, called, with, updated, search,
4

1 に答える 1

1

+2 つのトークンに分割されないように、式にa を追加するだけです。また、式を少し単純化することもできます。文字クラス内のすべての文字をエスケープする必要はありません。

String[] splitString = (EXAMPLE_TEST.split("[\\[\\],'\" (){}*.]+"));
于 2012-11-01T08:11:06.627 に答える