我有这种方法接收作为参数pdfText(这是一个字符串,包含解析后的pdf文件中的文本)和fileName这是我想写的文本文件找到一个字符串,并返回它后面的文字
但是现在我需要在这个文本中找到单词“Keywords”,并且只提取它后面的单词,它们在同一行(直到换行符)。
比如我有一个地方包含以下行
标题一文:东西。
“关键词:计算机,机器人,当然”
标签:标签1,标签2,标签3。
结果应该是以下列表[“计算机”,“机器人”,“课程”]。
解决问题
所以我搜索如何解决我question..here是一个解决方案,不是很聪明,但它的工作原理:
//index of first appearence of the word
int index = pdfText.indexOf("Keywords");
//string from that to the end
String subStr = pdfText.substring(index);
//index of first appearence of the new line in the new string
int index1 = subStr.indexOf("\n");
//the string we need
String theString = subStr.substring(9,index1);
System.out.println(theString);
//write in the file..use true as parameter for appending text,not overwrite it
FileWriter pw = new FileWriter(fileName,true);
pw.write(theString);
pw.close();
请出示一些尝试!仅仅因为你发布了代码并不意味着你会努力解决你的问题。 –
你可以通过让其他人做你的工作来获得A这个任务,但是你会在决赛中得到一个F。 –
提示:研究'String#split()''String#startsWith()' –