1
A
回答
3
虽然你的问题的标题是非常糟糕的感谢<str>
和</str>
之间
,我知道你到底是什么谈论,我之前遇到过麻烦。 解决方案使用的是Pattern。
一个简单的方法来获取是<str>
和</str>
(我猜可能只是东西在HTML不同)之间的字符串,是要做到这一点:第一
第一件事做初始化Pattern这样的:
Pattern pattern = Pattern.compile("<str>(.*?)</str>"); // (.*?) means 'anything'
然后,你想从它,做得到匹配:
Matcher matcher = pattern.matcher(<str>); //Note: replace <str> with your string variable, which contains the <str> and </str> codes (and the text between them).
接下来,德等候您是否希望找到本场比赛的最后一次出现,还是第一次,或全部,然后做这些:
First only
:
if (matcher.find()) { // This makes sure that the matcher has found an occurrence before getting a string from it (to avoid exceptions)
occurrence = matcher.group(1);
}
Last only
:
while(matcher.find()) { // This is just a simple while loop which will set 'n' to whatever the next occurrence is, eventually just making 'n' equal to the last occurrence .
occurrence = matcher.group(1);
}
All of them
:
while(matcher.find()) { // Loops every time the matcher has an occurrence , then adds that to the occurrence string.
occurrence += matcher.group(1) + ", "; //Change the ", " to anything that you want to separate the occurrence by.
}
Hopeful这有助于你:)
相关问题
- 1. 获取从包含特定字符串
- 2. GREP获得包含特定字符串的所有字符串
- 3. Laravel - 获得包含特定字符串
- 4. 从包含特定字符串的文本字段获取字符串
- 5. 如何获取包含指定数量空格的字符串?
- 6. 如何在字符串的特定子字符串之后获取字符串?
- 7. 如何替换包含python中特定字符的字符串?
- 8. 获取字符串的特定字符
- 9. 获取特定字符串,包括特定字符之间的特定字 - php
- 10. 如何从字符串(url)获取特定的字符串?
- 11. 发现其中id字符串包含特定字符串
- 12. 从字符串获取特定字符
- 13. 打印包含指定子字符串的所有字符串
- 14. MongoDB:如何过滤只包含特定字符的字符串?
- 15. 如何从包含“,”的字符串获取字符串值?
- 16. 如何获取字符串中的指定字符php
- 17. 如何从字符串中提取指定的字符串
- 18. Mysql包含字符串以获得列中的特定字符串
- 19. 如何从字符串的Arraylist中获取特定字符?
- 20. 抓取包含特定子字符串的特定修订号
- 21. 返回true是字符串包含特定字符在Javascript中
- 22. 从包含特殊字符的字符串中提取子串
- 23. 含有特定字符串
- 24. 不包含特定字符串
- 25. 字符串包含特定文本
- 26. 选择与包含特定字符串
- 27. 寻找forrecords包含特定字符串
- 28. Haskell计算包含字符串中特定字符的单词
- 29. Swift:如何在特定字符之前获取字符串?
- 30. StreamReader - 如何读取包含特定字符串的行?
它可能在这种情况下工作,但用正则表达式解析XML是一个坏主意。 – August 2014-11-22 19:26:55