| | |
Interestin dilemma - See if you can help :)
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 73
Reputation:
Solved Threads: 1
Hi,
I have stumbled on an interesting problem. I have thought 'n' thought, but haven't come up with any good ideas of how to handle this.
I have a text file that contains many records, but without the records being seperated. I need to figure out how to seperate these files, or at least how to write a program that recognizes different records and can then seperate them.
I don't expect anyone to write my program for me, but I need help seperating the records.
The beginning of every record looks like this: MSUBUGA JIMSON
P O BOX 21273
GABORONE
(Obviously they are all different, but always have 3 values on 3 lines.)
The end looks like this:
P107.17 P0.00 P225.08 P0.00 P332.25
(The numbers always vary, but there are always 5)
Any help will be greatly appreciated, Thank you.
I have stumbled on an interesting problem. I have thought 'n' thought, but haven't come up with any good ideas of how to handle this.
I have a text file that contains many records, but without the records being seperated. I need to figure out how to seperate these files, or at least how to write a program that recognizes different records and can then seperate them.
I don't expect anyone to write my program for me, but I need help seperating the records.
The beginning of every record looks like this: MSUBUGA JIMSON
P O BOX 21273
GABORONE
(Obviously they are all different, but always have 3 values on 3 lines.)
The end looks like this:
P107.17 P0.00 P225.08 P0.00 P332.25
(The numbers always vary, but there are always 5)
Any help will be greatly appreciated, Thank you.
1
#2 34 Days Ago
BufferedReader, readLine, a counter, and String's split.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Nov 2009
Posts: 73
Reputation:
Solved Threads: 1
0
#5 34 Days Ago
Eek!
Well, both ways worked. I handed in my project. Boss was satisfied.
The client gave us the wrong data though :/
Is there any way in java to determine whether or not a line of data is binary or text? e.g. it will always be one of the two.
Is there a method like [var].isBinary() or something? If so, which library should I import for it. I'm stumped. Googl'ing has proved fruitless so far, and I need to get this done by tomorrow this time.
Please help.
Well, both ways worked. I handed in my project. Boss was satisfied.
The client gave us the wrong data though :/
Is there any way in java to determine whether or not a line of data is binary or text? e.g. it will always be one of the two.
Is there a method like [var].isBinary() or something? If so, which library should I import for it. I'm stumped. Googl'ing has proved fruitless so far, and I need to get this done by tomorrow this time.
Please help.
I wanted to ask God for a bike, but I know thats not how he does things, so I stole one and asked for forgiveness.
0
#6 34 Days Ago
Well, text, is also "binary". If what you're reading might contain something that is not strictly plain text, then use a BufferedInputStream (with FileInputStream), rather than reader and convert the text parts to text with new String(byte[]).
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Nov 2009
Posts: 73
Reputation:
Solved Threads: 1
0
#7 34 Days Ago
•
•
•
•
Well, text, is also "binary". If what you're reading might contain something that is not strictly plain text, then use a BufferedInputStream (with FileInputStream), rather than reader and convert the text parts to text with new String(byte[]).
Im going to try the following:
Java Syntax (Toggle Plain Text)
byte bytearray [] = test.getBytes(); System.out.println("Test string : " + test); CharsetDecoder d = Charset.forName("US-ASCII").newDecoder(); try { CharBuffer r = d.decode(ByteBuffer.wrap(bytearray)); r.toString(); } catch(CharacterCodingException e) { System.out.println("only regular ASCII characters please!"); // interrupt the processing throw new Exception(e); } System.out.println("Ok, it's ASCII only!");
I wanted to ask God for a bike, but I know thats not how he does things, so I stole one and asked for forgiveness.
![]() |
Similar Threads
- Big Dilemma on upgrading RAM in a PC HP m7350la (Motherboards, CPUs and RAM)
- Inheritence/substitutability dilemma (C++)
- Internet explorer user problems (Web Browsers)
- Apache mod_rewrite with Google Ads (Linux Servers and Apache)
- usb memory stick (Windows NT / 2000 / XP)
- Can't get multimedia keys to work on mac keyboard (Apple Hardware)
- grokster/wupdater.exe/waol various... (Windows NT / 2000 / XP)
- spacial equilibrium (Geeks' Lounge)
Other Threads in the Java Forum
- Previous Thread: Access wamp functions programatically??
- Next Thread: What's the difference between a parent and predecessor node in binary search tree?
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class classes client code compile compiler component database developmenthelp draw eclipse error event exception fractal freeze game gameprogramming givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac map method methods mobile netbeans newbie notdisplaying number online oracle page print problem program programming project qt recursion scanner screen server set singleton size sms sort sql string swing system template textfields threads time title tree tutorial-sample update variablebinding windows working xor






