Foxtable(狐表)用户栏目专家坐堂 → 怎样判断字符串中有多少个汉字、英文字母和数字,还有空格?(笨办法搞定了)


  共有20559人关注过本帖树形打印复制链接

主题:怎样判断字符串中有多少个汉字、英文字母和数字,还有空格?(笨办法搞定了)

帅哥哟,离线,有人找我吗?
baoxyang
  1楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐精 帖子:3313 积分:23146 威望:0 精华:1 注册:2009/3/31 11:25:00
  发帖心情 Post By:2010/3/16 16:06:00 [显示全部帖子]

        dim s as string = "谢谢大家了 Thanks 39 aaaThanks 3333339     99"
         For i as integer = 1 to s.length           
              dim tt as integer = ASC(Mid(s,i,1)) 

               if  tt >= 65 and tt <= 90 then '为小写英文字母个数
                   n1 = n1 + 1
               end if
               if  tt >= 97 and tt <= 122 then '为大写英文字母个数
                   n2 = n2 + 1
               end if
                if  tt >= 48 and tt <= 57 then '为0~9数字个数
                   n3 = n3 + 1
               end if
                if  tt = 32 then '为空字符个数
                   n4 = n4 + 1
               end if

               if  tt < 0 then '为汉字个数
                   n5 = n5 + 1
               end if
        Next
output.show("字母: " & n1+n2 & " 数字: " & n3 & "  空格: " & n4 & "  汉字:  " & n5 & "  " & z.len

 回到顶部