I/P文件: doc,docx,en-dash,em-dash
我已经使用Apache Tika (元数据属性)和Aspose wordtojava(库)实现了字数统计功能,但它们不能给我提供准确的字数统计结果。
en-dash & em-dash字数与MS-Office ex不同。2-3 4-5结果: MS-office给出字数4对于上面的例子,APache - Tika & Aspose库给出字数2
如何计算与MS-Office给出的正确字数相同的字数?
任何帮助都是非常值得感谢的。
需要快速响应。
谢谢
发布于 2015-08-27 10:18:43
将文档中的所有字符串提取为一个字符串。使用这个正则表达式"\n\t\r\f \p{Pd}“拆分它们,并计算拆分的字符串数组的长度。
String allWords = "2—3 4–5";
String[] split = allWords.split("[\n\t\r\f \\p{Pd}]");
System.out.println(split.length);它打印了4。希望这对你有帮助。
发布于 2015-08-27 13:49:59
'BuiltInDocumentProperties.Words‘属性表示Word文档中的字数估计值。当您调用“Document.updateWordCount”方法时,Aspose.Words会更新此属性。请参考以下示例代码:
Document doc = new Document(getMyDir() + "in.docx");
// Update the word, character and paragraph count of the document.
doc.updateWordCount();
// Display the updated document properties.
System.out.println("Characters: " + doc.getBuiltInDocumentProperties().getCharacters());
System.out.println("Words: " + doc.getBuiltInDocumentProperties().getWords());
System.out.println("Paragraphs: " + doc.getBuiltInDocumentProperties().getParagraphs());霍普,这有帮助。
另外,请确保您使用的是latest version of Aspose.Words for Java,即15.7.0。
我与Aspose一起工作,作为开发人员的布道者。
发布于 2019-07-30 02:11:32
你可能还想看看https://github.com/maresja1/Word-Counter/blob/master/README.md,它使用Apache tika,可以处理doc,docx,rtf,pdf等。我看了代码,它实际上是一个字符计数器,可以删除重复的空格。但是可以很容易地将其更改为单词计数器。
https://stackoverflow.com/questions/32239427
复制相似问题