????D
2016-06-15 12:28
采纳率: 75%
浏览 2.8k
已采纳

vb.net的字符分割…怎么才能指定字符去分割我的字符串

“aaa”,“ddd”,“eee,eee,eee,”,“rrr”,123,“”
上面的字符串…怎么分割成下面这个样子…求指教

“aaa”
“bbb”
“eee,eee,eee,”
“rrr”
123
“”

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • ????D 2016-06-15 12:38
    已采纳

    分割前的字符串是连着的…

    已采纳该答案
    打赏 评论
  • threenewbee 2016-06-15 20:45
    Imports System
    Imports System.Collections.Generic
    
    Public Class Test
        shared function mysplit(s as string) as List(of string)
            dim arr as string() = s.Split(",")
            dim list as List(of string) = new List(of string)
            dim b as boolean = false
            dim buf as string
            for each i as string in arr
                if b then
                    if i.endswith(chr(34)) then
                        list.add(buf & "," & i)
                        buf = ""
                        b = false
                    else
                        buf = buf & "," & i
                    end if
                else
                    if i.startswith(chr(34)) then
                        if i.endswith(chr(34)) then
                            list.add(i)
                        else
                            buf = i
                            b = true
                        end if
                    else
                        list.add(i)
                    end if
                end if
            next
            return list
        end function
    
        Public Shared Sub Main()
            ' your code goes here
            dim s as string = """aaa"",""ddd"",""eee,eee,eee,"",""rrr"",123,"""""
            dim r as List(of string) = mysplit(s)
            for each s as string in r
                Console.WriteLine(s)
            next
        End Sub
    End Class 
    

    "aaa"
    "ddd"
    "eee,eee,eee,"
    "rrr"
    123
    ""

    http://ideone.com/FuII4q

    打赏 评论

相关推荐 更多相似问题