String 如何使PrintStream识别字符串中的回车符(unicode)?
我实际上是在尝试使用PrintStream将单个字符串写入包含换行符的文件,在这种情况下,我认为它将是一个回车符(CR)“\u000D”。至于这些换行符将发生在何处是未知的,所以我必须格式化字符串本身来进行换行,而不是让PrintStream进行 在这里,我在字符串中添加回车符(第行): 这里是我使用PrintStream将字符串打印到文本文件的地方:String 如何使PrintStream识别字符串中的回车符(unicode)?,string,unicode,ms-word,carriage-return,printstream,String,Unicode,Ms Word,Carriage Return,Printstream,我实际上是在尝试使用PrintStream将单个字符串写入包含换行符的文件,在这种情况下,我认为它将是一个回车符(CR)“\u000D”。至于这些换行符将发生在何处是未知的,所以我必须格式化字符串本身来进行换行,而不是让PrintStream进行 在这里,我在字符串中添加回车符(第行): 这里是我使用PrintStream将字符串打印到文本文件的地方: try { File file = new File(answer); PrintStream print = new Prin
try
{
File file = new File(answer);
PrintStream print = new PrintStream(file);
print.println(result);
}
//result is the same as the line string above once its all put together
我还检查了字符串,以找到哪里有回车符,并将其替换为其他字符,原因我将不深入讨论,因为这将是一个很长的解释。我使用以下命令在字符串中查找回车符:
String cr = System.getProperty("line.separator");
我遇到的问题是,在搜索文本时,它无法识别回车。此文本相当直接地取自Microsoft Word文档,这可能是问题的一部分。以下是当它不识别回车时捕捉到的信息:
//@@DEBUG -- KEEP THIS
String charValue = Character.toString(text.charAt(index));
try{
current[i] = alphaBits[Character.getNumericValue(text.charAt(index)) - 10][i];
}catch(ArrayIndexOutOfBoundsException e){
//@@DEBUG -- KEEP THIS
System.out.println("Unrecognized character: " + charValue);
Character whatIsThis = charValue.charAt(0);
String name = Character.getName(whatIsThis.charValue());
System.out.println("Unrecognized character name: " + name);
System.out.print("You may want to consider adding this character");
System.out.println(" to the list of recognized characters");
return "Unrecognized character found.";
}
所以我才发现我遇到的问题。我想这对任何人来说都很难理解,因为我没有解释translate()方法的作用。哎呀
if(useNLTranslator && !isNumber(section))
line = nlt.translate(line) + nlt.translate(System.getProperty("line.separator"));
在此之前,我没有翻译回车符/换行符,因此它无法识别,因为它的格式错误。谢谢你帮我解决这个问题 (1)如何从Microsoft Word获取文本?(2) 您是否在寻找换行符或“硬返回”/段落标记?Word不会标记由于内部换行而导致的换行,因此在.doc或.docx(我想)中不会有可检测的字符代码。1)我想我应该说,我实际上是将Microsoft Word文件中的内容转换为文本文件(.txt)。2) 我希望能得到硬回报和软回报,但我没有想到软回报。有没有办法抓住软回报?
if(useNLTranslator && !isNumber(section))
line = nlt.translate(line) + nlt.translate(System.getProperty("line.separator"));