解析字符串数组或数据表
问题描述:
我试图解析长枯燥的文本文档,并解析和格式化。解析字符串数组或数据表
"7/29/2012 1:25:20 PM","Summary Plan/Second Floor /Master_VAV_2-24","Source :OEnd"
"7/29/2012 11:25:23 AM","Summary Plan/Second Floor /Master_VAV_2-24","Source :OStart"
我想解析引号之间的每个值,但我不能找到任何东西在网上帮我,我相信这是知道该怎么称呼它和搜索的问题。
“日期”,“位置”,“类型”将是3个值我想将它解析为,然后我可以运行在数据表中每个项目的循环,并根据需要对其进行格式化。
任何帮助会很好,谢谢!
我想用正则表达式来获得行和手动添加到一个数组中,这样的事情的。
Dim rx As New Regex(",", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
Dim matches As MatchCollection = rx.Matches(strSource)
For Each match As Match In matches
Dim matchValue As String = match.Value
If Not list.Contains(matchValue) Then
list.Add(matchValue)
End If
Next
答
这种格式似乎是CSV - 使用许多免费和开源的CSV解析器之一(谷歌“.NET CSV分析器”将返回很多结果
有一个自带内置,在Microsoft.VisualBasic.FileIO
namespece - 在TextFieldParser