gpt4 book ai didi

java - 尝试从在某些标签之间读取的缓冲读取器中提取子字符串

转载 作者:行者123 更新时间:2023-12-01 14:57:39 24 4
gpt4 key购买 nike

我正在使用 bufferedreader 提取 5 个网页,每个网页之间用空格分隔,我想使用子字符串来提取每个页面的 url、html、源代码和日期。但我需要有关如何正确使用子字符串来实现此目的的指导,干杯。

public static List<WebPage> readRawTextFile(Context ctx, int resId) {   

InputStream inputStream = ctx.getResources().openRawResource(
R.raw.pages);

InputStreamReader inputreader = new InputStreamReader(inputStream);
BufferedReader buffreader = new BufferedReader(inputreader);
String line;
StringBuilder text = new StringBuilder();

try {
while ((line = buffreader.readLine()) != null) {


if (line.length() == 0) {
// ignore for now
//Will be used when blank line is encountered
}

if (line.length() != 0) {
//here I want the substring to pull out the correctStrings
int sURL = line.indexOf("<!--");
int eURL = line.indexOf("-->");
line.substring(sURL,eURL);
**//Problem is here**
}
}
} catch (IOException e) {
return null;

}
return null;
}

最佳答案

我想你想要的是这样的,

public class Test {
public static void main(String args[]) {
String text = "<!--Address:google.co.uk.html-->";
String converted1 = text.replaceAll("\\<!--", "");
String converted2 = converted1.replaceAll("\\-->", "");
System.out.println(converted2);
}

}

结果显示:地址:google.co.uk.html

关于java - 尝试从在某些标签之间读取的缓冲读取器中提取子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14149919/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com