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

ASP.NET
ewebeditor在.net的使用方法
Server.Transfer,Response.Redirect的区别
ASP.NET2.0+SQL Server2005构建多层应用
ASP.NET 2.0 中收集的小功能点(转)
ASP.Net全局变量的设置和读取方法
数据库开发总结(ADO.NET小结)
ASP.net(c#)打造24小时天气预报及实时天气
发布WEB站点时出现Server Application Unavailable
在asp.net中实现datagrid checkbox 全选的方法
ASP.NET 2.0 URL映射技巧
ConfiguraionSource节点及多个配置文件的应用
SqlConnection.ConnectionString相关关键字
如何在WebForm中使用javascript防止连打(双击)
看到本质而不是现象--解决ASP.NET CS0016的问题
学会区分Visual Studio 2005,Visual Studio 2005 Team System和MSDN Premium 订阅的各个版本
ASP.NET 入门的五个步骤
ASP.NET 高性能分页代码
动态ItemTemplate的实现(译) - item,template
遍历Hashtable 的几种方法
通过VS中的数据源选择对话框简单实现数据库连接配置

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


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