对字符串中各字符逐一进行判断,给相应计数加一即可,实现方法如下:
假设字符串为 strTmp,大写计数intUc,小写计数intLc,数字计数intNum,其它计数intOth
dim i as integer,chrTmp as string
intUc=0
intLc=0
intNum=0
intOth=0
for i=1 to len(strTmp)
chrTmp=mid(strTmp,i,1)
if (chrTmp>="A") and (chrTmp<="Z") then
intUc=intUc+1
elseif (chrTmp>="a") and (chrTmp<="z") then
intLc=intLc+1
elseif (chrTmp>="0") and (chrTmp<="9") then
intNum=intNum+1
else
intOth=intOth+1
endif
next
print intUc,intLc,intNum,intOth
此段代码只提示解决思路,不进行优化(如对循环上限赋值变量,而不是每循环一次计算一次)