10-11-2006, 12:10 PM | #1 (permalink) |
Free Mars!
Location: I dunno, there's white people around me saying "eh" all the time
|
[Java] StringBuffer ignoring captalized letters
I have an assignment that is to read from a file that is too large for RandomFileAccess to use. So, instead I'm using FileChannel through MappedByteBuffer reader so that the memory doesn't get overloaded. The first method extract word is to extract the word from inputted file. The second method findNextLetter is to find the next letter as long as it is [a-z][A-Z].
Code:
private static String extractWords(MappedByteBuffer readBuffer) { StringBuffer word = new StringBuffer(); byte nextByte = readBuffer.get(); while((nextByte > 64 && nextByte < 91) || (nextByte > 96 && nextByte < 123)) { word.append((char)nextByte); nextByte = readBuffer.get(); } if(readBuffer.hasRemaining()) findNextLetter(readBuffer); return word.toString(); } private static void findNextLetter(MappedByteBuffer readBuffer) { byte nextByte = readBuffer.get(); while((nextByte > 64 && nextByte < 91) || !(nextByte > 96 && nextByte < 123)) { nextByte = readBuffer.get(); } readBuffer.position(readBuffer.position() - 1); } Code:
WASHINGTON (CNN) -- North Korea's claims of a nuclear test establish Pyongyang as a "threat to international peace," President Bush said Wednesday as he pledged to defend U.S. allies and interests in the region. Code:
WASHINGTON orth orea s claims of a nuclear test establish yongyang as a threat to international peace resident ush said ednesday as he pledged to defend allies and interests in the
__________________
Looking out the window, that's an act of war. Staring at my shoes, that's an act of war. Committing an act of war? Oh you better believe that's an act of war |
10-11-2006, 05:54 PM | #2 (permalink) |
Crazy
|
Do you want a not (!) on the first part of the while loop in the findNextLetter method?
__________________
Even if you stop the clock, it gives the right time twice a day. Once we get out of the eighties, the nineties are going to make the sixties look like the fifties. |
Tags |
captalized, ignoring, java, letters, stringbuffer |
|
|