当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 解决CSV字段数据带有双引号的问题

ASP.NET
关于.NET动态代理的介绍和应用简介
ASP.NET2.0服务器控件之类型转换器
ASP.net做的IP访问限制
Asp.Net2.0权限树中Checkbox的操作
ASP.NET数据库编程之Access连接失败
ASP.NET 2005 Treeview终极解决方案
ASP.NET数据库编程之处理文件访问许可
ASP.NET 2.0中的页面输出缓存
ASP.NET 2.0服务器控件开发之复杂属性
ASP.NET2.0中数据源控件之异步数据访问
將datagrid控件內容輸出到excel文件
ASP.NET技巧:教你制做Web实时进度条
实现基于事件通知的.Net套接字
ASP.NET技巧:同时对多个文件进行大量写操作对性能优化
ASP.NET中根据XML动态创建使用WEB组件
QQ关于.net的精彩对话
ASP.NET技巧:access下的分页方案
为自己的ASP网站系统构建一套标记语言
Visual Studio.Net 内幕(6)
Asp.Net中NHiernate的Session的管理

ASP.NET 中的 解决CSV字段数据带有双引号的问题


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 133 ::
收藏到网摘: n/a

主要解决CSV字段数据带有双引号的问题

具体代码如下:

以下为引用的内容:

        Public Function ChangeCsvSplitLine(ByVal strLine As String, ByVal iColNumber As Integer) As String()
        Dim strList() As String = strLine.Split(",")
        If strList.Length = iColNumber Then
        Return strList
        End If

        Dim i As Integer = 0
        Dim findSplitIndex As Integer = -1
        Dim index As Integer = 0
        Dim returnList(iColNumber) As String
        Dim strMerger As String = ""
        For i = 0 To strList.Length - 1
        If findSplitIndex = -1 Then
        If (strList(i)(0) = """" And strList(i)(strList(i).Length - 1) <> """") _
        Or (strList(i).Length = 1 And strList(i) = """") Then
        findSplitIndex = i
        Else
        returnList(index) = strList(i)
        index = index + 1
        End If
        Else
        If (strList(i)(0) <> """" And strList(i)(strList(i).Length - 1) = """") _
        Or (strList(i).Length = 1 And strList(i) = """") Then
        strMerger = ""
        For findSplitIndex = findSplitIndex To i
        strMerger = strMerger & strList(findSplitIndex) & ","
        Next
        strMerger = strMerger.Substring(0, strMerger.Length - 1)
        returnList(index) = strMerger
        index = index + 1
        findSplitIndex = -1
        End If
        End If
        Next
        Return returnList
        End Function