【发布时间】:2014-12-11 06:03:36
【问题描述】:
对于我正在编写的程序,我在字符串中存储了来自 html 文件的信息。 html 文件是导出的书签文件,我需要我的程序搜索 html 文件并将每个实例存储到特定站点的书签,以便我可以进行进一步处理。
书签有一致的开始,但没有一致的结束,例如
https://www.example.net/e/1111111/1/example
https://www.example.net/e/2222222/1/
https://www.example.net/e/3333333/1
https://www.example.net/e/4444444
在 html 文件中,url 后面是一个引号,但我不确定如何使用它来获取 url。
如果有人能指出我正确的方向,感激不尽
感谢@mafagafogigante 的帮助,它允许我生成以下代码:
public static void FileforURL(String content){
int first, second;
while(content.indexOf("https://www.example.net/e/") != -1){
first = content.indexOf("https://www.example.net/e/");
if(content.indexOf("\"",first) != -1){
second = content.indexOf("\"",first);
try {
URL(content.substring(first, second));
} catch (Exception e) {
e.printStackTrace();
}
content = content.substring(second,content.length());
}
}
}
【问题讨论】:
标签: java string search substring