简体   繁体   中英

Parse from formatted string Java

I want to extract from a String formatted information. Let's say I have these parameters that I want to fill from my String.

    String apperanceNumber;
    String docNumber;
    String organisation;
    String publishedDate;
    String closingDate;
    String amdendmentNumber;
    String noticeTitle;

And that I want to get information from that kind of string:

1       
12-0017     
Transportation - Construction / Transports - Construction       
2012/01/26  
2012/02/13 11:00
PAVING - ROUTE 425 DUNNETS ROAD AREA TOWARD SCHENKELS LANE


2   
0622028 
DSS, CIMS       
2012/01/25      
2012/02/13 13:30        
Computer forensic tools

I looked into String methods available, and I am pretty sure it is not the good way to to it.

You could try using regular expressions. Here's a tutorial on that:

http://docs.oracle.com/javase/tutorial/essential/regex/

With regular expressions, you can read a whole document and identify where does a string belong based on how it is written.

Hope it helps!

check out flatworm . it will do all the magic for you, creating java objects from the text file automatically. you'll want to read about the multi-line record support, but it's in there and I think will do exactly what you're wanting

If your data always has one line for each parameter they you can read lines and assign the values to each variable. You need to adjust according to format.

If you are writing the output from java program and reading it in java then you can make use of java serialization/deserialization.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM