'字數統計
Public Class Form1
'重覆計算版
'Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Dim str2 = ""
' Dim i
' Dim c
' Dim str1 = "明天會更好,後天會更好,天天更好。明天會更好,後天會更好,天天更好明天會更好,後天會更好,天天更好。明天會更好,後天會更好,天天更好"
' ' MsgBox("字串長度為:" & str1.ToString.Length)
' Dim j
' For j = 1 To str1.ToString.Length
' c = 0
' For i = 1 To str1.ToString.Length
' If Mid(str1, i, 1) = Mid(str1, j, 1) Then c = c + 1
' Next
' str2 = str2 & Mid(str1, j, 1) & "->共有:" & c & "個" & vbNewLine
' Next
' MsgBox(str2)
'End Sub
'不重覆計算版
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strChk = ""
Dim str2 = ""
Dim i
Dim c
Dim str1 = "明天會更好,後天會更好,天天更好。明天會更好,後天會更好,天天更好明天會更好,後天會更好,天天更好。明天會更好,後天會更好,天天更好"
' MsgBox("字串長度為:" & str1.ToString.Length)
Dim j
For j = 1 To str1.ToString.Length
If InStr(strChk, Mid(str1, j, 1)) = 0 Then
c = 0
For i = 1 To str1.ToString.Length
If Mid(str1, i, 1) = Mid(str1, j, 1) Then c = c + 1
Next
str2 = str2 & Mid(str1, j, 1) & "->共有:" & c & "個" & vbNewLine
strChk = strChk & Mid(str1, j, 1)
End If
Next
MsgBox(str2)
End Sub
End Class
沒有留言:
張貼留言