vb.net查找字母个数 vb输入字符串统计字母个数
vb程序,怎样统计文本框中大写英文字母、小写英文字母及数字的个数,希望有注释
Private Sub Form_Load()
网站的建设成都创新互联公司专注网站定制,经验丰富,不做模板,主营网站定制开发.小程序定制开发,H5页面制作!给你焕然一新的设计体验!已为成都玻璃贴膜等企业提供专业服务。
Command1.Enabled = False '使Command1不可用
Label2.Visible = False '使Label2、...、Label7不可见
Label3.Visible = False
Label4.Visible = False: Label5.Visible = False
Label6.Visible = False: Label7.Visible = False
Label8.Visible = False: Label9.Visible = False
'Text1.TabIndex = 0 '使文本框获得输入焦点
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Command1.Enabled = True '输入结束,使Command1可用
End Sub
Private Sub Command1_Click() '单击Command1完成统计
Dim s As String, length As Integer, s1 As String
Dim n1 As Integer, n2 As Integer, n3 As Integer, wt As Boolean, n4 As Integer
s = Text1.Text
length = Len(s)
n1 = 0: n2 = 0: n3 = 0
For i% = 1 To length
s1 = Mid(s, i%, 1)
If s1 = "a" And s1 = "z" Or s1 = "A" And s1 = "Z" Then
n1 = n1 + 1 '字母字符
ElseIf s1 = "0" And s1 = "9" Then
n2 = n2 + 1 '数字字符
Else
n3 = n3 + 1 '其它字符
End If
Next i%
Label5.Caption = n1: Label6.Caption = n2
Label7.Caption = n3: Label2.Visible = True '显示标签
Label3.Visible = True: Label4.Visible = True
Label5.Visible = True: Label6.Visible = True
Label7.Visible = True
For i% = 1 To length '这个循环找到第一个单词的字母
s1 = Mid(s, i%, 1)
If s1 = "a" And s1 = "z" Or s1 = "A" And s1 = "Z" Then Exit For
Next i%
wt = False
For j% = i To length '从第一个单词的字母开始统计
s1 = Mid(s, j%, 1)
If s1 = "a" And s1 = "z" Or s1 = "A" And s1 = "Z" Then
If wt = False Then
n4 = n4 + 1
wt = True
End If
Else
wt = False
End If
Next j%
Label8.Visible = True: Label9.Visible = True
Label9.Caption = n4
End Sub
vb.net.问题:通过文本框输入一串字符,单击命令按钮,要求分别统计字符串中所含字母和数字的个数。
要改成这样;
for i = 1 to Len(s)
j = Mid(s,i,1)
select case j
case "a" to "z","A" to "Z"
C = C + 1
CASE "0" TO "9"
D = D + 1
CASE ELSE
M= M+1
END SELECT
NEXT
vb 中获取某个字符的个数
统计某个字符的代码如下:
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
vb 统计字母出现的个数的函数
Private Sub Command1_Click()
Dim n As Integer
Dim i As Integer
Dim one As Integer
n = 0
For i = 1 To Len(Text1.Text)
one = Asc(Mid(Text1.Text, i, 1))
If (one = 65 And one = 90) Or (one = 97 And one = 122) Then n = n + 1
Next i
MsgBox "共有" n "个字母。"
End Sub
在“通用声明”代码区声明(窗体)模块级变量
Option Explicit
Dim letters As Integer '声明模块级变量,此变量计算字母个数
Dim space As Integer '空格个数
Dim digit As Integer '数字个数
Dim others As Integer '其他字符个数
输入cmdStat_Click()事件过程代码
Private Sub cmdStat_Click()
Dim InputStr As String '局部变量,此变量存储输入的字符串
Dim i As Integer '循环控制变量,整型
Dim CaseStr As String '此变量保存储所截取的字符
letters = 0 '初始化为0
space = 0
digit = 0
others = 0
InputStr = txtInput.Text '取得输入的字符串
For i = 1 To Len(InputStr) '开始分别统计个数
CaseStr = Mid(InputStr, i, 1) '取得某个字符
Select Case CaseStr
Case "a" To "z", "A" To "Z" '如果字符是英文字母
letters = letters + 1
Case " " '如果字符是空格
space = space + 1
Case 0 To 9 '如果字符是数字
digit = digit + 1
Case Else '如果字符是其他字母
others = others + 1
End Select
Next
'以下代码用来显示统计出的结果值
txtResult1.Text = letters
txtResult2.Text = space
txtResult3.Text = digit
txtResult4.Text = others
txtResult5.Text = Len(InputStr)
End Sub
在VB中如何统计字母出现的个数 急用。注明,两个文本框,一个输入,一个统计,故需要两个程序代码。谢谢了
两个文本框,一个command按钮
Private Sub Command1_Click()
Dim i As Long
Dim CharNum As Long
CharNum = 0
For i = 1 To Len(Text1.Text)
If (Asc(Mid$(Text1.Text, i, 1)) = 65 And Asc(Mid$(Text1.Text, i, 1)) = 90) Or (Asc(Mid$(Text1.Text, i, 1)) = 97 And Asc(Mid$(Text1.Text, i, 1)) = 122) Then
CharNum = CharNum + 1
End If
Next
Text2.Text = "字母出现次数:" CharNum
End Sub
怎么用VB编写一个能查出1串字符中,各个英文字母的个数
private
sub
command1_click()
n
=
m
=
k
=
l
=
aa
=
bb
=
text1
do
until
len(bb)
=
aa
=
asc(bb)
bb
=
right(bb,
len(bb)
-
1)
aa
if
97
=
aa
and
aa
=
122
then
n
=
n
+
1
else
if
65
=
aa
and
aa
=
90
then
m
=
m
+
1
else
if
48
=
aa
and
aa
=
57
then
k
=
k
+
1
else
l
=
l
+
1
end
if
end
if
end
if
loop
picture1.print
"小写字母为";
n;
"个"
picture1.print
"大写字母为";
m;
"个"
picture1.print
"数字为";
k;
"个"
picture1.print
"特殊符号为";
l;
"个"
end
sub
你再调调
当前名称:vb.net查找字母个数 vb输入字符串统计字母个数
标题来源:http://scyanting.com/article/hisgsg.html