vfp程序设计 如何统计一句话中汉字和字母的个数
答案:2 悬赏:40 手机版
解决时间 2021-04-26 17:28
- 提问者网友:星軌
- 2021-04-25 19:15
vfp程序设计 如何统计一句话中汉字和字母的个数
最佳答案
- 五星知识达人网友:渊鱼
- 2021-04-25 19:27
CLOSE ALL
CLEAR ALL
CLEAR
ACCEPT "请输入一句话:" TO cMyStr
IF EMPTY(cMyStr)
?"没有输入字符!"
RETURN
ENDIF
cMyStr = ALLTRIm(cMyStr)
?"您输入的这句话中"
?"有 " + ALLTRIm(STR(LEN(cMyStr) - LENC(cMyStr))) + " 个汉字(含全角符号);"
nNumEngCnt = 0
nUppEngCnt = 0
nLowEngCnt = 0
nOthEngCnt = 0
FOR nLoop_01 = 1 TO LEN(cMyStr)
DO CASE
CASE BETWEEN(ASC(SUBSTr(cMyStr, nLoop_01, 1)), 48, 57)
nNumEngCnt = nNumEngCnt + 1
CASE BETWEEN(ASC(SUBSTr(cMyStr, nLoop_01, 1)), 65, 90)
nUppEngCnt = nUppEngCnt + 1
CASE BETWEEN(ASC(SUBSTr(cMyStr, nLoop_01, 1)), 97, 122)
nLowEngCnt = nLowEngCnt + 1
CASE ASC(SUBSTr(cMyStr, nLoop_01, 1)) > 128
nLoop_01 = nLoop_01 + 1
OTHERWISE
nOthEngCnt = nOthEngCnt + 1
ENDCASE
NEXT
?"有 " + ALLTRIm(STR(nNumEngCnt)) + " 个数字;"
?"有 " + ALLTRIm(STR(nUppEngCnt)) + " 个大写英文字母;"
?"有 " + ALLTRIm(STR(nLowEngCnt)) + " 个小写英文字母;"
?"有 " + ALLTRIm(STR(nOthEngCnt)) + " 个其它符号。"
RETURN
CLEAR ALL
CLEAR
ACCEPT "请输入一句话:" TO cMyStr
IF EMPTY(cMyStr)
?"没有输入字符!"
RETURN
ENDIF
cMyStr = ALLTRIm(cMyStr)
?"您输入的这句话中"
?"有 " + ALLTRIm(STR(LEN(cMyStr) - LENC(cMyStr))) + " 个汉字(含全角符号);"
nNumEngCnt = 0
nUppEngCnt = 0
nLowEngCnt = 0
nOthEngCnt = 0
FOR nLoop_01 = 1 TO LEN(cMyStr)
DO CASE
CASE BETWEEN(ASC(SUBSTr(cMyStr, nLoop_01, 1)), 48, 57)
nNumEngCnt = nNumEngCnt + 1
CASE BETWEEN(ASC(SUBSTr(cMyStr, nLoop_01, 1)), 65, 90)
nUppEngCnt = nUppEngCnt + 1
CASE BETWEEN(ASC(SUBSTr(cMyStr, nLoop_01, 1)), 97, 122)
nLowEngCnt = nLowEngCnt + 1
CASE ASC(SUBSTr(cMyStr, nLoop_01, 1)) > 128
nLoop_01 = nLoop_01 + 1
OTHERWISE
nOthEngCnt = nOthEngCnt + 1
ENDCASE
NEXT
?"有 " + ALLTRIm(STR(nNumEngCnt)) + " 个数字;"
?"有 " + ALLTRIm(STR(nUppEngCnt)) + " 个大写英文字母;"
?"有 " + ALLTRIm(STR(nLowEngCnt)) + " 个小写英文字母;"
?"有 " + ALLTRIm(STR(nOthEngCnt)) + " 个其它符号。"
RETURN
全部回答
- 1楼网友:大漠
- 2021-04-25 19:50
没有字数统计吗?
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯