按键精灵如何查找字串中相同字符数量?
1个回答
展开全部
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个不同字符,这应该是一篇短文了。。。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询