有四個字串ab,ac,ab,ab
相同的保留下來即可,
即只剩下ab,ac
請協助解答謝謝!
2006-02-02 11:28:33 · 1 個解答 · 發問者 cat 1 in 電腦與網際網路 ➔ 程式設計
ab(x1)與ac(x2),可以直接作比較嗎?例if x1x2
2006-02-02 12:17:57 · update #1
還有是否可以使用陣列來作,x(0)=ab,x(1)=ac,x(2)=ab,x(3)=ab
2006-02-02 12:25:12 · update #2
Private Sub Command1_Click()
Dim S As String, S1 As String, Str As String
Str = "," & "ab,ac,ab,ab" & ","
Do
'先找出左邊第一個字串值
S = Left(Str, InStr(2, Str, ",", vbTextCompare) - 1)
'記錄到S1
S1 = S1 & S
'移除Str內跟S相同的所有字串
Str = Replace$(Str, S, "")
Loop Until Str = "," '直到Str=","為止
'輸出S1
Print Right(S1, Len(S1) - 1)
End Sub
2006-02-02 20:55:40 補充:
我想不管直接比較或是用陣列來做其實都可以,但若直接取值再一個一個的跟原字串去比較,效率可能不太好吧!!
2006-02-02 12:11:55 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋