0

基本的に 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.";
}
4

1 に答える 1

0

だから私は実際に私が抱えていた問題を理解しました。そして、translate() メソッドが何をするのか説明しなかったので、これを理解するのは誰にとっても難しかったと思います。おっとっと。

if(useNLTranslator && !isNumber(section))
    line = nlt.translate(line) + nlt.translate(System.getProperty("line.separator"));

以前は改行/行区切り記号を翻訳していなかったので、形式が間違っていたため認識されませんでした。この問題で私を助けてくれてありがとう!

于 2014-05-18T19:24:01.007 に答える