按键精灵查找字串中相同字符数量
按键精灵查找字串中相同字符数量,例如:字串="你,我,他,他,你,我,我,你,他,我,他,你"请问如何快速计算出:你字出现的的个数是?我字个数?他字个数?字串不固定的,谢...
按键精灵查找字串中相同字符数量,例如:
字串="你,我,他,他,你,我,我,你,他,我,他,你"
请问如何快速计算出:你字出现的的个数是?我字个数?他字个数?
字串不固定的,谢谢。。。也就是说,可能会出现:
字串="a,b,c,d,e,f,g"
等等,那个字串是未知值
这题是按键5级考试题目,要求写个函数,前面的字串函数都写好了,困惑在字串再分解计算,昨天晚上几个小时研究测试,终于简化地写出了语句,今早上看考试结果:通过
文件名="a,a,a,a,a,d,,,,g,,g,r,,er,d,,d,s,,s,f,,,d,,g,,,"//等等某个不固定字符串
Do Until 文件名=""
文件名q=""
MyArray = Split(文件名, ",")
tt=tt&"*"& MyArray(0)&"="&UBound(Split(文件名,MyArray(0)))&"|"
i=1
For UBound(Split(文件名, MyArray(0)))
文件名q = 文件名q & Split(文件名, MyArray(0)&",")(i)
i=i+1
Next
文件名=文件名q
Loop
MessageBox tt 展开
字串="你,我,他,他,你,我,我,你,他,我,他,你"
请问如何快速计算出:你字出现的的个数是?我字个数?他字个数?
字串不固定的,谢谢。。。也就是说,可能会出现:
字串="a,b,c,d,e,f,g"
等等,那个字串是未知值
这题是按键5级考试题目,要求写个函数,前面的字串函数都写好了,困惑在字串再分解计算,昨天晚上几个小时研究测试,终于简化地写出了语句,今早上看考试结果:通过
文件名="a,a,a,a,a,d,,,,g,,g,r,,er,d,,d,s,,s,f,,,d,,g,,,"//等等某个不固定字符串
Do Until 文件名=""
文件名q=""
MyArray = Split(文件名, ",")
tt=tt&"*"& MyArray(0)&"="&UBound(Split(文件名,MyArray(0)))&"|"
i=1
For UBound(Split(文件名, MyArray(0)))
文件名q = 文件名q & Split(文件名, MyArray(0)&",")(i)
i=i+1
Next
文件名=文件名q
Loop
MessageBox tt 展开
3个回答
展开全部
Dim a(100),jl(100),cs(100)
str="你","我","他","他","你","我","我","你","他","我","他","你","明","天","大","家","明","天"
b=split(str,",")
i=0
p = 0
q=0
n=0
Rem pd
sm = 1
For UBound (b)+1
c = b(i)
d = b(p + 1)
If CStr(c) = CStr(d) Then
TracePrint sm
sm = sm + 1
End If
If p<Ubound(b)-1 Then
p=p+1
Else
Exit For
End If
Next
jl(n) = b(i)
cs(n) = sm
If sm > 1 Then
a(q) = b(i)
q=q+1
End If
Rem pd2
i = i + 1
p = i
For qq=0 to ubound(a)
cc = len(a(qq))
If cc = 0 Then
Exit for
End If
Next
For pp=0 to qq
If a(pp) = b(i) and i<ubound(b)+1 Then
Goto pd2
End If
Next
If i<ubound(b)+1 then
n = n + 1
Goto pd
End if
For m=0 to n
TracePrint jl(m) & "出现" & cs(m) & "次"
Next
笨办法,看在150分的份上。
以上代码,字符串可以随机,分隔符一定要是逗号,变量保存在几个数组中,a是相同字,jl是所有不同字,cs是单个字符出现次数。dim声明数组可以设随机大,如果不同字符超过100个,就设200,超过200个不同字符,这应该是一篇短文了。。。
str="你","我","他","他","你","我","我","你","他","我","他","你","明","天","大","家","明","天"
b=split(str,",")
i=0
p = 0
q=0
n=0
Rem pd
sm = 1
For UBound (b)+1
c = b(i)
d = b(p + 1)
If CStr(c) = CStr(d) Then
TracePrint sm
sm = sm + 1
End If
If p<Ubound(b)-1 Then
p=p+1
Else
Exit For
End If
Next
jl(n) = b(i)
cs(n) = sm
If sm > 1 Then
a(q) = b(i)
q=q+1
End If
Rem pd2
i = i + 1
p = i
For qq=0 to ubound(a)
cc = len(a(qq))
If cc = 0 Then
Exit for
End If
Next
For pp=0 to qq
If a(pp) = b(i) and i<ubound(b)+1 Then
Goto pd2
End If
Next
If i<ubound(b)+1 then
n = n + 1
Goto pd
End if
For m=0 to n
TracePrint jl(m) & "出现" & cs(m) & "次"
Next
笨办法,看在150分的份上。
以上代码,字符串可以随机,分隔符一定要是逗号,变量保存在几个数组中,a是相同字,jl是所有不同字,cs是单个字符出现次数。dim声明数组可以设随机大,如果不同字符超过100个,就设200,超过200个不同字符,这应该是一篇短文了。。。
展开全部
a = "你,我,他,他,你,我,我,你,他,我,他,你"
b = Split(a, "你")
c = Split(a, "我")
d = Split(a, "他")
MessageBox "你的数量"&UBound (b)&",我的数量"&UBound (c)&",他的数量"&UBound (d)
b = Split(a, "你")
c = Split(a, "我")
d = Split(a, "他")
MessageBox "你的数量"&UBound (b)&",我的数量"&UBound (c)&",他的数量"&UBound (d)
追问
字串不固定的,抱歉,没说清楚
追答
字符串不固定脚本:
str = "你,我,他,他,你,我,我,你,他,我,他,你"
Redim a(len(str))
for i = 0 To UBound (a)
a(i)=Mid(str,i+1,1)
Next
For i = 0 To UBound (a)-1
If Instr(b, a(i)) = 0 Then
b=b & a(i)
End If
Next
Redim c(len(b))
for i = 0 To UBound (c)
c(i)=Mid(b,i+1,1)
Next
For i = 0 To UBound (c)-1
d = split(str, c(i))
e = e & ubound(d)&"个"&c(i)&","
next
MessageBox e
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
其中的要查找的词是固定的?
追问
不固定的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询