swp3h6
asked on
Sorting entries in a text file
my problem goes like this:
I have a text file filled with entries that each have a category name and delimiter in front of them, kindof like the following:
Category1::blahblahblahbla hblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah
Category2::blahblahblahbla hblahblahb lahblahbla hblahblahb lahblahbla hblah blahblahblahblahblah blahblahblahblahblah
Category1::blahblahblahbla hblahblahb lahblahbla hblahblahb lahblahbla hblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah
and so forth....
I'd like to sort these entries by their categories and print the results to a new text file like this:
Category1
blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah
blahblahblahblahblahblahbl ahblahblah blahblahbl ahblahblah blah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah
Category 2
blahblahblahblahblahblahbl ahblahblah blahblahbl ahblahblah blah blahblahblahblahblah blahblahblahblahblah
========================== ==========
what would be the easiest way to do this?
I have a text file filled with entries that each have a category name and delimiter in front of them, kindof like the following:
Category1::blahblahblahbla
Category2::blahblahblahbla
Category1::blahblahblahbla
and so forth....
I'd like to sort these entries by their categories and print the results to a new text file like this:
Category1
blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah
blahblahblahblahblahblahbl
Category 2
blahblahblahblahblahblahbl
==========================
what would be the easiest way to do this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
is this homework?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
okay, i'll try these things out.
And no its not homework, just work.
And no its not homework, just work.
StringList sl = new StringList();
sl.read("x.txt");
Collections.sort(sl);
sl.save("sorted-x.txt");
sl.read("x.txt");
Collections.sort(sl);
sl.save("sorted-x.txt");
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for all the input everyone, but I never got any kind of Collections thing to work for me. I solved the problem by using a 2 dimentional array to sort the entries by category.
That is also possible, but using Collections, you prevent writing a lot of code because you wil use the in-built API :)