我有這種方法接收作爲參數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()' –