统计某个字符的代码如下:
Private Sub Command1_Click()
Dim i As Integer, Ccount As Integer
For i = 1 To Len(Text1)
If Mid(Text1, i, 1) = "你所需要统计的字符" Then Ccount = Ccount + 1
Next i
msgbox "共有" & Count & "个e"
End Sub
Private Sub Command1_Click()
Dim s As String, temp As String
Dim i As Integer, e As Integer, c As Integer
s = Text1text
c = 0
e = 0
For i = 1 To Len(s)
temp = Mid$(s, i, 1)
If Asc(temp) >= 33 And Asc(temp) <= 126 Then
e = e + 1
Else
If Asc(temp) < 0 Then
c = c + 1
End If
End If
Next i
EnumbCaption = CStr(e)
CnumbCaption = CStr(c)
End Sub
Private Sub Command2_Click()
Text1text = ""
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
If DataGetFormat(vbCFText) Then
Text1text = DataGetData(vbCFText)
End If
If DataGetFormat(vbCFFiles) Then
Dim vfn
For Each vfn In DataFiles
DropFile Text1, vfn
Next vfn
End If
End Sub
Private Sub Text1_OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)
If DataGetFormat(vbCFText) Or DataGetFormat(vbCFFiles) Then
Effect = vbDropEffectCopy And Effect
Exit Sub
End If
Effect = vbDropEffectNone
End Sub
Sub DropFile(ByVal text As TextBox, ByVal strfn$)
Dim iFile As Integer
iFile = FreeFile
Open strfn For Input Access Read Lock Read Write As #iFile
Dim str$, strline$
While Not EOF(iFile) And Len(str) <= 32000
Line Input #iFile, strline$
DebugPrint strline
If str <> "" Then str = str & vbcflf
str = str & strline
Wend
Close #iFile
textSelStart = Len(text)
textSelLength = 0
textSelText = str
End Sub
Option Explicit
Private Sub Command1_Click()
Dim i As Integer
Dim stra As String
Dim a As Integer
For i = 1 To Len(Text1Text)
stra = Mid(Text1Text, i, 1)
MsgBox "当前字母为:" & stra & " 添加分析即可"
'利用ASC的值区分字母数字字符等,因为要统计的太多了不多说,只教方法
' if Asc(stra)= 91 then
Next
End Sub
Private Sub Command1_Click()
Dim str As String, strTmp As String, intN As Integer, intM As Integer
Dim intX As Integer, intY As Integer, intZ As Integer, intW As Integer
str = Text1Text
intN = Len(str)
For intM = 1 To intN
strTmp = UCase(Mid(str, intM, 1))
If IsNumeric(strTmp) Then '数字
intX = intX + 1
ElseIf Asc(strTmp) > 64 And Asc(strTmp) < 91 Then '字母
intY = intY + 1
ElseIf strTmp = " " Then '空格
intZ = intZ + 1
Else '其它
intW = intW + 1
End If
Next
Text2Text = "数字个数为:" & intX
Text3Text = "字母个数为:" & intY
Text4Text = "空格个数为:" & intZ
Text5Text = "特殊字符个数为:" & intW
End Sub
'如果满意我的回答,请采纳谢谢
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)