我不知道如何找到这些词.. 示例我有这个文本...
The other day I went to the <location> and bought some <plural-noun> . Afterwards, I went to <location> , but it was very <adjective> so I left quickly and went to <location> .
<
当我在谷歌上搜索时,我不知道要搜索什么原因>
,它将被忽略。需要帮助如何获取此字符串。
所以我会得到<location>
, <plural-noun>
, <location>
, <adjective>
,<location>
我必须使用charAt()
方法。我的尝试:
String string = this.fileName;
for(int i = 0; i < string.length(); i++)
if((string.charAt(i) == '<') && (string.charAt(i) == '>'))
System.println(""); //<-------- IM STUCK HERE
不知道……快两天没睡了。
我当前但最后一个问题...如何删除<
和>
显示的每个单词?
String string = this.template;
Pattern pattern = Pattern.compile("<.*?>");
Matcher matcher = pattern.matcher(string);
List<String> listMatches = new ArrayList<String>();
while(matcher.find()) {
listMatches.add(matcher.group());
}
// System.out.println(listMatches.size());
int indexNumber = 1;
for(String s : listMatches) {
System.out.println(Integer.toString(indexNumber) + ". " + s);
indexNumber++;
}