psychopixi
01-05-2006, 09:37 PM
If anyone can offer help, I'd be very happy! :D
I have to write a program in java for my coursework, and part of it involves reading in strings from a file. That's all fine and dandy.
Once I have the string, I need to get the separate characters. For example, if my string is "otcl" I need to have "o", "t", "c" and "l".
I know how to iterate through the string to get separate characters, but the length of the strings vary - from 1 to 6 characters. I need to get the separate characters, and compare them to the characters from subsequent strings.
It's possible I'm being incredibly stupid about this, seeing as I've been working on it for ages, and my brain's beginning to shut down... but...
If I'm iterating through the string, and I don't know how long it will be, how do I keep track of the characters?
This is my code so far:
CharacterIterator charIt = new StringCharacterIterator(cLikes);
// Iterate over the characters in the forward direction
for (char c = charIt.first(); c != CharacterIterator.DONE ; c = charIt.next() )
{
//get the separate characters
}
Am I being really stupid? I had the idea of creating an array list, and adding c in on each iteration. Is that a bad idea?
Gah, I hate coursework.
I have to write a program in java for my coursework, and part of it involves reading in strings from a file. That's all fine and dandy.
Once I have the string, I need to get the separate characters. For example, if my string is "otcl" I need to have "o", "t", "c" and "l".
I know how to iterate through the string to get separate characters, but the length of the strings vary - from 1 to 6 characters. I need to get the separate characters, and compare them to the characters from subsequent strings.
It's possible I'm being incredibly stupid about this, seeing as I've been working on it for ages, and my brain's beginning to shut down... but...
If I'm iterating through the string, and I don't know how long it will be, how do I keep track of the characters?
This is my code so far:
CharacterIterator charIt = new StringCharacterIterator(cLikes);
// Iterate over the characters in the forward direction
for (char c = charIt.first(); c != CharacterIterator.DONE ; c = charIt.next() )
{
//get the separate characters
}
Am I being really stupid? I had the idea of creating an array list, and adding c in on each iteration. Is that a bad idea?
Gah, I hate coursework.