基本的に PrintStream を使用して、改行を含むファイルに単一の文字列を書き込もうとしています。この場合、キャリッジ リターン (CR) '\u000D' になると思います。これらの改行がどこで発生するかは不明であるため、PrintStream で改行を行うのではなく、文字列自体をフォーマットして改行を行う必要があります。
ここで、文字列 (行) にキャリッジ リターンを追加します。
if(useNLTranslator && !isNumber(section))
line = nlt.translate(line) + System.getProperty("line.separator");
ここでは、PrintStream を使用して文字列をテキスト ファイルに出力します。
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.";
}