我已經使用JAVA中的PDFBOX讀取PDF文件並將數據轉換爲文本並保存在字符串中。我發現很多文本數據被X'C2A0'包圍。例如:字符串中的java十六進制數據
X'436C756233AC2A04469616D6F6E64C2A0' Club:__Diamond__
__是X'C2A0'
我想搜索「俱樂部:__,那麼2爲__之間解析 「鑽石」 我已經試過類似:
String TAG = "\\xC2A0"; // Tag in PDF
int pos = text.indexOf(TAG, positionInText);
但我從來沒有得到任何安打如何指定TAG
編輯:?
也許做個進一步的說明n是必需的。我使用PDFBOX:
public void toText() throws IOException
{
this.pdfStripper = null;
this.pdDoc = null;
this.cosDoc = null;
file = new File(filePath);
parser = new PDFParser(new RandomAccessFile(file,"r")); // update for PDFBox V 2.0
parser.parse();
cosDoc = parser.getDocument();
pdfStripper = new PDFTextStripper();
pdDoc = new PDDocument(cosDoc);
pdDoc.getNumberOfPages();
pdfStripper.setStartPage(1);
pdfStripper.setEndPage(10);
// reading text from page 1 to 10
// if you want to get text from full pdf file use this code
// pdfStripper.setEndPage(pdDoc.getNumberOfPages());
text = pdfStripper.getText(pdDoc);
文本是一個字段定義爲字符串。這個文本字符串是我試圖解析的。
令人困惑的問題。什麼是'\\ xC2A0'?你能發表一個實際的例子嗎? – shmosel
爲什麼不TAG =「俱樂部」? – brummfondel
十六進制是錯誤的,'33'應該只是一個'3'。如果將十六進制轉換爲字節,然後使用UTF-8進行解碼,則會得到'Club:_Diamond_',其中兩個下劃線分別是'C2A0'(UTF-8)又名'''NO-BREAK SPACE'(U + 00A0)] (http://www.fileformat.info/info/unicode/char/00a0/index.htm)。它是單個NBSP字符('A0')的2字節UTF-8編碼。 – Andreas