从格式化字符串 Java 中解析

发布于 2025-01-04 10:50:07 字数 611 浏览 1 评论 0原文

我想从字符串中提取格式化信息。 假设我想从字符串中填充这些参数。

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

我想从这种字符串中获取信息:

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

我研究了可用的 String 方法,并且我很确定这不是实现它的好方法。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

仙女 2025-01-11 10:50:07

您可以尝试使用正则表达式。这是有关该内容的教程:

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

使用正则表达式,您可以阅读整个文档并根据字符串的编写方式识别字符串所属的位置。

希望有帮助!

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!

浅沫记忆 2025-01-11 10:50:07

查看扁虫。它会为你完成所有的魔法,自动从文本文件创建 java 对象。您需要阅读有关多行记录支持的信息,但它就在那里,我认为它会完全满足您的要求

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

呆° 2025-01-11 10:50:07

如果您的数据始终为每个参数占一行,您可以读取行并将值分配给每个变量。您需要根据格式进行调整。

如果您正在编写java程序的输出并在java中读取它,那么您可以使用java序列化/反序列化。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文