i know how to read a line from a text file, but how do i deal with a file like this? i want to read one string at a time
as always, first things first. How do you define a string?
My guess is you can't. You may have to read it a character at a time and stop when you get to whatever is your delimiter, or read the entire thing and parse it, or use something else (like sed or awk) to break it apart first...
Why do you need to read one string at a time?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I remember doing something like this when I was working on Euler problems. I was working with Ruby and Python, neither of which I understood well, but the concepts should be the same. I remember two basic approaches:
Read a line
Break it up on the comma delimiter
Read a line
Remove first and last characters (both quotation marks)
Break remaining string up on the "," delimiter
The first seems more elegant somehow, but the second might be faster.
it seems the entire file is one line "A","ABILITY","ABLE",..."YOURSELF","YOUTH"
it seems to me keeping the quotes would be a good thing.
perhaps you are right though.
btw it is Euler42 i am working on.
perhaps if i do this
String values = bufferedReader.readLine().split(",");
for(int i = 0; i < values.length; i++)
String x = values[i];
or do i have to remove the quotes?
personally, i would argue that it doesn't matter. the purpose is to compute the score of each word and see if it is a triangle number.
I don't see any reason why you couldn't do some pre-processing on the input file. I would personally run it through something that replaces the "," with a newline, delete any extraneous double quotes, and then eyeball the file to make sure it is what I wanted.