Кто-нибудь имеет представление о том, что здесь может происходить?
Первый блок показывает то, что я, как правило, ожидаю увидеть - первый символ строки находится в индексе '0' с закомментированной строкой 'problem', замененной точно такой же вещью, однако никогда не выполнявшейся раньше.
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
*/
Второй блок имеет закомментированную «новую» строку, а первый символ «wordOne» - ничто. Это не нулевой символ или перевод строки. Я использовал эту переменную, чтобы найти запятые в '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, что может вызвать такую проблему? Я попытался использовать массивы символов, очистить рабочее пространство, чтобы перестроить все, и ничего не изменилось… Это огромная проблема для поиска индексов «ngrams» в предложениях, когда некоторые граммы - это такие вещи, как «и». В какой-то момент прошлой ночью он работал, а потом неожиданно начал не работать. Я в замешательстве.
Есть идеи?
Спасибо
Andrew