2009年5月4日 星期一

字數統計

image

'1算多少個半形字母含空白 38
'2算多少個英文字母不含空白,含標點符號 30
'3算多少個英文字母不含空白,不含標點符號 28
'4算多少個英文字 9
'5算有多少個e 6
'6統計分別各有多少個字母 W: 1   h: 3  e: 6 ....
Public Class Form1
    Dim i, c, j
    Dim str1 = ""
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim s = " Where there is a will,   there is a way."
        'ans1
        'MsgBox(s.length)

        'ans2
        'For i = 1 To s.length
        '    If Mid(s, i, 1) <> " " Then c = c + 1
        'Next
        'MsgBox(c)

        'ans3
        'For i = 1 To s.length
        '    If Mid(s, i, 1) <> " " And Mid(s, i, 1) <> "," And Mid(s, i, 1) <> "." Then c = c + 1
        'Next
        'MsgBox(c)

        'ans4
        'For i = 2 To s.length
        '    If Mid(s, i, 1) = " " And Mid(s, i - 1, 1) <> " " Then c = c + 1
        'Next
        'MsgBox(c + 1)

        'ans5
        'For i = 1 To s.length
        '    If Mid(s, i, 1) = "e" Then c = c + 1
        'Next
        'MsgBox(c)

        'ans6
        For j = 1 To s.length
            If InStr(str1, Mid(s, j, 1)) = 0 Then
                c = 0
                For i = 1 To s.length
                    If Mid(s, i, 1) = Mid(s, j, 1) Then c = c + 1
                Next
                str1 = str1 & Mid(s, j, 1) & " : " & c & vbNewLine
            End If
        Next
        MsgBox(str1)
    End Sub
End Class

沒有留言:

張貼留言