请帮我编一个简单的VB程序
来源:百度知道 编辑:UC知道 时间:2024/05/31 04:38:57
编写程序,输入一个字符串,统计其中字母"a"的个数,
如输入"abcda 12e*af",则输出: 3 .
如输入"abcda 12e*af",则输出: 3 .
一楼二楼都对,我也来个简单方法
dim s as string
s="abcda 12e*af"
msgbox len(s)-len(Replace(s,"a",""))
dim s as string
dim i as byte
dim count as byte
s="abcda 12e*af"
for i = 1 to len(s)
if mid$(s,i,1)="a" then
count = count + 1
end if
next i
给你一个多叉树来解决这个问题吧,相比别的代码,这个应该最快
添加一个List用来统计每一个字符并显示,添加一个textbox来设置要制作的随即文本大小,添加两个按钮,一个是开始统计,一个是制作随即文本。
统计那么少的字符没意思,试一试统计上兆的文本吧。
Option Explicit
Dim txtString() As Byte
Private Sub Command2_Click()
On Error Resume Next
'分析字符数量
Dim tim As Single: tim = Timer
Dim words(25) As Long
Dim i As Long
Dim c As Long
c = UBound(txtString)
Do
Select Case txtString(i)
Case 97 To 122
words(txtString(i) - 97) = w