2012年11月20日 星期二

消除字串

試寫一程式,以輸入一字串,其長度 (含空白), 最長為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."

3 則留言:

  1. Dim temp As String
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    strr = Split("a e i o u A E I O U", " ")
    Do
    Input #1, temp
    For i = 0 To 9
    temp = Replace(temp, strr(i), "")
    Next
    Print #2, temp
    Loop Until EOF(1)
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  2. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    m = Split("A,E,I,O,U,a,e,i,o,u", ",")
    Do Until EOF(1)
    Line Input #1, x
    For i = 0 To 9
    x = Replace(x, m(i), "")
    Next
    Print #2, x
    Loop
    Close
    Close
    End
    End Sub

    回覆刪除
  3. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Do
    Line Input #1, n
    If n <> "" Then
    Print #2, n
    n = Replace(n, "A", "")
    n = Replace(n, "a", "")
    n = Replace(n, "E", "")
    n = Replace(n, "e", "")
    n = Replace(n, "I", "")
    n = Replace(n, "i", "")
    n = Replace(n, "O", "")
    n = Replace(n, "o", "")
    n = Replace(n, "U", "")
    n = Replace(n, "u", "")
    Print #2, n
    Print #2, ""
    End If
    Loop Until EOF(1)
    Close #2
    Close #1
    End
    End Sub

    回覆刪除