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

ASP.NET
.net基础知识错误注意二十二点知识
用.NET动态创建类的实例讲解
微软发布.NET Framework 3.5 SP1正式版
asp.net教程:HTTP状态码200,301,302
.NET 2.0中Hashtable快速查找的方法
在ASP.Net Ajax中调用WebService
asp.net 和 access 联合开发的分页类
ASP.NET 全局异常处理
用SQL语句完成SQL Server数据库的修复
.net 框架程序设计
ASP.NET结合XML编写计数器
ASP.NET水晶报表实现打印功能
Asp.Net中设计与使用水晶报表
防止ASP.NET按钮多次提交的办法
.NET开发事件处理的步骤
ASP.NET刷新页面的六种方法
Asp.net ajax实现任务提示页面
ASP.NET 2.0中XML数据的处理
ASP.NET中XML数据的处理
Jadu: 将 PHP 编译成 .NET

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 84 ::
收藏到网摘: 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