題目是:當我隨便輸入一串數字但把每個數字只取出來一次,且有重複的數字也只取一次
例如: 654327324
解:654327
例如: 7894321873
解:7894321
例如: 66889997952
解:689752
2005-10-28 06:32:33 · 4 個解答 · 發問者 非凡 1 in 電腦與網際網路 ➔ 程式設計
也就是說每個不同的數字我只要取出一個
2005-10-28 06:37:49 · update #1
Dim a(99)
Private Sub Command1_Click()
t = Text1
For i = 1 To Len(t)
a(i) = Mid(t, i, 1)
Next i
For i = 1 To Len(t)
n = 0
For j = 1 To Len(t)
n = n + 1
If a(i) = a(i + n) Then a(i + n) = ""
Next j
Next i
For i = 1 To Len(t)
If a(i) <> "" Then
Text2 = Text2 & a(i)
End If
Next i
End Sub
=====================
我的做法
先把字做成陣列
之後做
把重複的變成空的就好^^
最後就是答案了
2005-10-31 13:07:07 補充:
我不會用你的方法呢..感覺陣列比價快呢@.@"..
2005-10-28 06:50:49 · answer #1 · answered by 小毛 5 · 0⤊ 0⤋
Private Sub Command1_Click()
Dim S As String, S1 As String
S = "7894321873"
Do
S1 = S1 & Left(S, 1)
S = Replace(S, Left(S, 1), "")
Loop Until Len(S) = 0
MsgBox S1
End Sub
2005-10-28 09:48:06 · answer #2 · answered by W.J.S. 7 · 0⤊ 0⤋
strIn = "654327324"
For i = 1 To Len(strIn)
strGet = Mid(strIn, i, 1)
If InStr(strOut, strGet) = 0 Then
strOut = strOut & strGet
End If
Next i
MsgBox strOut
好好利用InStr函數
簡單說,就是每次都取一個數字出來,放到strOut變數中
因為不曉得到底要取幾個,乾脆也不比對來源資料
只要用InStr函數來搜尋strOut變數,當這次從strIn取出的數字已經存在
於strOut時,就不做字串連結,繼續取下一個,若找不到就加到strOut裡
2005-10-28 11:03:08 補充:
給小毛~~別想的太複雜,這題還用不到陣列~~ v_v
2005-10-28 07:02:09 · answer #3 · answered by 釋放後的快樂 2 · 0⤊ 0⤋
不懂
2005-10-28 06:33:42 · answer #4 · answered by Anonymous · 0⤊ 0⤋