对于我编写的程序,我将 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());
}
}
}
最佳答案
使用 String.indexOf(...) 获取下一个“https://[...]”子字符串开头。
重复查找所需下一个子字符串的开头。
获取中间的文本。
重复直到得到 -1,剩下的就是您的最后一个 URL。
关于java - 获取两个其他子字符串之间的子字符串的每个实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26394786/