Re: [VBA ] 請問如何剖析文字串

看板Visual_Basic作者 (矇面加菲獅)時間17年前 (2007/04/08 15:15), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/4 (看更多)
※ 引述《myidname (你碰不得的男人)》之銘言: : 請問版上大大 : 若我有一個string被空白或者豆號分開 : 示意如下 " year , what line go " : 這個自串前後都有空白,其間使用空白或豆號隔開 : 當空白或豆號的位置不定 : 要如何解析出year,what,line,go這四個不同單字 : 感激不盡~ Public Function Parse(ByVal src As String) As Variant Dim i1 As Integer, c As String, s As String Dim arr As Variant, e As Variant, result As String arr = Split(src, vbCrLf) '假設有換行符號存在 For Each e In arr e = Trim(e): i2 = 1 Do While Len(e) > 0 i1 = i1 + 1 If i1 > Len(e) Then c = " " Else c = Mid(e, i1, 1) If c = " " Or c = "," Then s = Left(e, i1 - 1): e = Trim(Mid(e, i1 + 1)): i1 = 0 If s <> "" Then If result <> "" Then result = result & "," result = result & s End If End If Loop Next Parse = Split(result, ",") '傳回一個陣列 End Function -- ▃▅▇▆▄ ▆▂▃ ` 逝去感如何能留住,半點遺留殊不易,██▅▇▄▃ ▇▃▂" . █████████▃i ▁▄▇ 更多悽悽慘慘的遭遇………██▆▃ █▅▆▃ˍ▄* ▂█▄▇▅▂. 我不知道,王~八~蛋~~! ▂▆███ █▄▃ 。fumizuki。Check。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.194.224.174
文章代碼(AID): #1669P-OA (Visual_Basic)
討論串 (同標題文章)
文章代碼(AID): #1669P-OA (Visual_Basic)