简体   繁体   English

如何在Java的数组列表中搜索字符串的特定格式?

[英]how do i search an arraylist for a specific format of a string in Java?

I am trying to search an arraylist, not for a value but for a format. 我正在尝试搜索一个arraylist,而不是一个值,而是一个格式。 I am importing a text file that is inconsistent in formatting. 我正在导入格式不一致的文本文件。 I have successfully imported the information into a 2D arraylist . 我已成功将信息导入到2D arraylist Is there a way to scrub the info for a format of a string? 有没有一种方法可以清除字符串格式的信息?

example imported info: 导入信息示例:

14  03-324-27216|14     "1 = 14' 0"" X 3.500""" 14.000  49      3.500   MF AU 210 AS M  0   05-01-15    

14  03-362-50502|14 24543   "1 = 21' 6"" X 3.625""" 21.000  77      3.625   BF GP 212           
            Location REM                                
            V:24543 

Each line of the imported file may contain multiple dimensions and multiple lines. 导入文件的每一行可能包含多个维度和多行。 I would like to start a new Arraylist when the format 我想在格式化时开始一个新的Arraylist

##-###-#####|## 

shows up, and add an element any time that 出现,并在任何时候添加元素

"# = ##' #"" x #.###""" 

show up. 出现。

From the two lines you posted it appears that is a space delimited CSV file. 从您发布的两行看来,这是一个以空格分隔的CSV文件。 The downside is that some 'empty' elements were written as a space. 缺点是一些“空”元素被写为空格。

If you replace spaces with commas (unless they have a space on both sides) you get a properly formatted CSV file. 如果您用逗号替换空格(除非它们两边都有空格),您将获得格式正确的CSV文件。

03-324-27216|14, , ,"1,=,14',0"",X,3.500""",14.000,,49, ,, ,3.500, ,MF,AU,210,AS,M,,0, ,05-01-15, ,,
03-362-50502|14,24543, ,"1,=,21',6"",X,3.625""",21.000,,77, ,, ,3.625, ,BF,GP,212, ,, ,, , ,

It may be easier to build a custom CSV parser that handles the weird 3 spaces in a row case. 构建自定义CSV解析器以处理行中奇怪的3个空格可能更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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