-4

我想以相同的顺序多次拆分一个非常长的字符串,其中包括日期、时间和一些评论,如何使用 java 将它们分别拆分为日期、时间和评论。

例如:

21 March 2012 3:48 PM 11 doz 30 September 2011 10:51 AM Hotlist Task Deleted: To-do Ring re: Boody (Jessica ordered socks)With: 3 Beaches Chemist Deleted by: MASTER 21 September 2011 12:55 PM Hotlist Task Created: To-do Ring re: Boody (Jessica ordered socks) With: 3 Beaches Chemist Scheduled by: MASTER Assigned to: MASTER 21 September 2011 12:55 PM 7 doz

我想要输出为:

Date              Time     Comments
21 March 2012     3:48 PM  11 doz
30 September 2011 10:51 AM Hotlist Task Deleted: To-do Ring re: Boody (Jessica ordered socks)With: 3 Beaches Chemist Deleted by: MASTER
21 September 2011 12:55 PM Hotlist Task Created: To-do Ring re: Boody (Jessica ordered socks) With: 3 Beaches Chemist Scheduled by: MASTER Assigned to: MASTER
21 September 2011 12:55 PM 7 doz
4

4 回答 4

0

我还建议使用正则表达式来匹配您想要破坏字符串的条件。

您也可以放置一个分隔符,让正则表达式知道要破坏字符串。

于 2012-04-11T11:58:10.610 回答
0

我建议创建一个算法,根据您知道的格式查找起息日字符串(例如,查找与某个月份匹配的下一个字符串)并据此分解字符串。找到月份,备份直到找到日期并拆分。

于 2012-04-11T11:55:08.440 回答
0
s.replaceAll ("([0-3]?[0-9] [A-Z][a-z]+ 20[0-9][0-9] )", "\n$1")

结果:

21 March 2012 3:48 PM 11 doz 
30 September 2011 10:51 AM Hotlist Task Deleted: To-do Ring re: Boody (Jessica ordered socks)With: 3 Beaches Chemist Deleted by: MASTER 
21 September 2011 12:55 PM Hotlist Task Created: To-do Ring re: Boody (Jessica ordered socks) With: 3 Beaches Chemist Scheduled by: MASTER Assigned to: MASTER 
21 September 2011 12:55 PM 7 doz
于 2012-04-28T12:01:12.983 回答
0

您可以尝试使用正则表达式,但条目之间必须有一个行/条目分隔符。

于 2012-04-11T11:42:56.513 回答