ここで何が起こっているのか知っている人はいますか?
最初のブロックは、私が一般的に期待するものを示しています。文字列の最初の文字はインデックス「0」にあり、「問題」の文字列はコメントアウトされ、まったく同じものに置き換えられますが、前に実行されることはありません。
public void finderTest(){
String theDoc = "Hello, I want this to work, and work well! Do you think it will work, and if not, why not?";
//String wordOne = "abc"; // old, pre-used string, used to hold a comma.
String wordOne = "abc";// new, never run before with a comma
String wordTwo = "and";
System.out.println("Type of character at index '0' in theDoc: "+Character.getType(theDoc.charAt(0)));
System.out.println("Character at index '0' in theDoc: "+theDoc.charAt(0));
System.out.println();
System.out.println("All of wordOne: "+"'"+wordOne+"'");
System.out.println("Type of character at index '0' in wordOne: "+Character.getType(wordOne.charAt(0)));
System.out.println("Character at index '0' in wordOne: "+wordOne.charAt(0));
System.out.println();
System.out.println("Type of Character at index '0' in wordTwo: "+Character.getType(wordTwo.charAt(0)));
System.out.println("Character at index '0' in wordTwo: "+wordTwo.charAt(0));
}
出力が得られます:
/*
Type of character at index '0' in theDoc: 1
Character at index '0' in theDoc: H
All of wordOne: 'abc'
Type of character at index '0' in wordOne: 2 // okay
Character at index '0' in wordOne: a // okay
Type of Character at index '0' in wordTwo: 2
Character at index '0' in wordTwo: a
*/
2 番目のブロックには、コメント アウトされた 'new' 文字列があり、'wordOne' の最初の文字は何もありません。null 文字や改行ではありません。その変数を使用して 'theDoc' 内のカンマを見つけていましたが、実行すると、インデックス '0' には何も保持されず、インデックス 1 にはカンマが含まれていました。文字列をコピーして貼り付けると、問題は残ります。ただし、コメントアウト/削除すると、問題が解消されます。
public void finderTest(){
String theDoc = "Hello, I want this to work, and work well! Do you think it will work, and if not, why not?";
String wordOne = "abc"; // now running old string, used to hold comma
//String wordOne = "abc";
String wordTwo = "and";
System.out.println("Type of character at index '0' in theDoc: "+Character.getType(theDoc.charAt(0)));
System.out.println("Character at index '0' in theDoc: "+theDoc.charAt(0));
System.out.println();
System.out.println("All of wordOne: "+"'"+wordOne+"'");
System.out.println("Type of character at index '0' in wordOne: "+Character.getType(wordOne.charAt(0)));
System.out.println("Character at index '0' in wordOne: "+wordOne.charAt(0));
System.out.println();
System.out.println("Type of Character at index '0' in wordTwo: "+Character.getType(wordTwo.charAt(0)));
System.out.println("Character at index '0' in wordTwo: "+wordTwo.charAt(0));
}
出力が得られます:
/*
Type of character at index '0' in theDoc: 1
Character at index '0' in theDoc: H
All of wordOne: 'abc'
Type of character at index '0' in wordOne: 16 // What does this mean?
Character at index '0' in wordOne: // where is the a? (well, its in wordOne index '1'... but why??)
Type of Character at index '0' in wordTwo: 2
Character at index '0' in wordTwo: a
*/
このような問題を引き起こす Java のコンマや記号について何かありますか? 文字配列を使用して、ワークスペースをクリーンアップしてすべてを再構築しようとしましたが、これは何も変わりませんでした…一部のグラムが「、および」のようなものである場合、これは文内の「ngram」のインデックスを見つけるための大きな問題です。昨夜、ある時点で機能していましたが、突然機能しなくなりました。私はかなり混乱しています。
何か案は?
ありがとう、
アンドリュー