首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >标记化后列表中的空格

标记化后列表中的空格
EN

Stack Overflow用户
提问于 2012-11-01 16:01:36
回答 1查看 99关注 0票数 1

我有一个单词列表,在标记化之后,我在列表中得到了一些我实际上不想要的空格。请给我建议。

示例字符串

代码语言:javascript
复制
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.....

以下是代码和输出片段

代码语言:javascript
复制
String[] splitString = (EXAMPLE_TEST.split("[\\[\\],\\'\"  \\(\\)\\{\\}\\*\\.]"));

输出

代码语言:javascript
复制
nsIAutoCompletResult, , no, , Simple, , , , so, the, QI, fails, , historyResult

在某些地方我看到了这样的..。

代码语言:javascript
复制
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,
EN

回答 1

Stack Overflow用户

发布于 2012-11-01 16:11:07

只需在表达式中添加一个+,以避免在两个标记之间拆分。您还可以稍微简化您的表达式,您不必转义字符类中的所有这些字符:

代码语言:javascript
复制
String[] splitString = (EXAMPLE_TEST.split("[\\[\\],'\" (){}*.]+"));
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13173134

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档