This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes need to delimit string to get into parts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "need to delimit string to get into parts" Watch "need to delimit string to get into parts" New topic
Author

need to delimit string to get into parts

John Smith
Greenhorn

Joined: May 11, 2007
Posts: 13
I've currently setup the code



and it reads in the text file fine, but I need to be able to delimit my input into two strings based on the ; that appears in the line. Here is my current print out

21806000300231;5847
21806000327226;
21806000273164;114
21806000274170;8245
21806000334313;
21806000115043;4220
21806000403274;1313

and i need to read each number into a string array separately so that i have something like

string[1] = 21806000300231
string2[1] = 5847


i've searched for some example code, but haven't ran across any yet.

thanks
sudhir nim
Ranch Hand

Joined: Aug 29, 2007
Posts: 212

You can use split() function

Example


[Servlet tutorial] [Servlet 3.0 Cook Book]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37879
    
  22
Originally posted by sudhir nim:
You can use split() function.
But always check here
that you are not using a metacharacter in your split() argument. I think ; is a normal character.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

In this case the CSV file can be read using split(), but for more complex files, where the values can contain ; as well, I'd suggest opencsv.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need to delimit string to get into parts
 
Similar Threads
java io question, conceptual query
bufferedreader / accessing file
DataOutputstream writeshort doesnt work
Little help with reading files
Read LDIF contents and Display in Tree