試寫一程式,以輸入一字串,其長度 (含空白), 最長為81個字元,然後檢驗該語言串中之母音 (A,E,I,O,U,a,e,i,o,u),並將之刪除,且該 些母音之位置由後續之字元向前位移予以佔用而不留下空白,例:輸入
"Mary^Lives^IN^300,^Born^St.,^Chungli,^Taiwan,^R.^O.^C." 其中"^" 表示空一個位置。
經刪除母音後成為 "Mry^Lvs^N^300,^Brn^St.,^Chngl,^Twn,^R.^.^C." ;然後將輸入之字串與刪除母音後之字串同時列印於報表。
測試資料:(請將下列文章存於檔案中,以讀檔案的方式來設計程式)
" He Sells Sea Shells by the Seashore."
" I don't know how to Complete the testing Program."
" The men who spead ill of others will take no
advantage of others in the last."
Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
a = "a e i o u A E I O U"
b = Split(a)
Do While Not EOF(1)
Input #1, x
For i = 0 To 9
x = Replace(x, b(i), "")
Next
Print #2, x
Loop
Close
Close
End
End Sub
小冰好,
回覆刪除程式正確。
用replace來解這題是很容易的。
它原來是設計成用陣列或是連結資料形態的,那麼缺了一格的,後面要重新連結是有些辛苦的。
但是,用replace就沒這些狀況。
Private Sub Form_Load()
回覆刪除Me.Hide
mw = "a e i o u"
m = Split(mw)
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Do While Not EOF(1)
Line Input #1, x
For i = 0 To 4
x = Replace(x, m(i), "")
Next i
Print #2, x
Loop
Close #2
Close #1
End
End
End Sub