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

ASP.NET
DataList绑定到Row[]行集合的问题的方法
充分利用ASP.NET的三种缓存提高站点性能的注意方法
asp.net下文件上传和文件删除的代码
asp.net下日期加减的方法
asp.net动态载入用户控件的方法
asp.net下定制日期输出格式的代码
C#正则用法两例
asp.net图片上传生成缩略图的注意事项
ASP.NET中高质量缩略图的生成代码
DataList 中动态绑定服务器子控件的代码
asp.net下URL网址重写成.html格式、RSS、OPML的知识总结
使用UserControl做网站导航条的思路 分析
ASP.NET中使用AspnetAccessProvider
asp.net下实现URL重写技术的代码
为大家经常为md5加密过的常用admin,admin888,0000密码
利用MS AJAX注册Javascript命名空间并创建类
asp.net(c#)中取得文件物理路径
垃圾代码二三行 ASPX小马
.NET 2.0获取配置文件AppSettings和ConnectionStrings节数据的方法
.NET c# 单体模式(Singleton)

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


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