✔ 最佳答案
1.計算含有a,o,u 單字
Dim s As String = "we are the world. We are the children."
Dim a() As String
Dim i As Integer
Dim w, x, y, z As Integer
a = Split(s, " ")
For i = 0 To a.Length - 1
w = InStr(a(i), "a")
x = InStr(a(i), "o")
y = InStr(a(i), "u")
If w > 0 Or x > 0 Or y > 0 Then
z = z + 1
End If
Next
Debug.Print("含有 a,o,u 三個字元的單字共有 " & z & " 個")
2.輸入 I am a teacher 將其反轉
Dim s As String
Dim a() As String
Dim b As String
Dim i As Integer
s = InputBox("請輸入所要反轉的文字")
a = Split(s, " ")
For i = a.Length - 1 To 0 Step -1
b = b & a(i) & " "
Next
Debug.Print(b)
2014-01-04 17:20:26 補充:
第二題如果不是自由輸入則可刪除 s = InputBox 那列,
並把 Dim s As String 改成
Dim s As String = "I am a teacher"
2014-01-05 13:33:21 補充:
我沒用過 Strreverse 函數, 不過剛剛試了, 發現輸出結果是以字母為單位反轉, 而不是版大要的以單字為單位的反轉, 因此可能不適在本題.
2014-01-06 11:30:53 補充:
我覺得樓上OrAnGe*韋 的寫法不錯, 用 UBound 才是常見的寫法, 所以第二題我也抄他修改如下
Dim s As String = "I am a teacher"
Dim a() As String
Dim b As String
Dim i As Integer
a = Split(s, " ")
For i = UBound(a) To 0 Step -1
b = b & a(i) & " "
Next
Debug.Print(b)