vfp 输入一段文本(内容包括汉字和英文字符)。编写一个程序,统计出汉字数量和英文字符数量。

求过程,谢谢。真的不会啊~~~~~

第1个回答  2013-05-31
clea
accept "请输入:" to a
n=len(a)
zifu=0
hanzi=0
for i=1 to n
if ASC(substr(a,i,2))>=45120
hanzi=hanzi+1
i=i+1
else
zifu=zifu+1
endif
endfor
?"该段文本包含英文字符"+alltrim(str(zifu))+"个。"
?"该段文本包含中文字符"+alltrim(str(hanzi))+"个。"
第2个回答  2013-05-31
假如输入的a只有中文和英文,不含空格和其他符号
accept "请输入:" to a
n=len(a)
zifu=0
hanzi=0
for i=1 to n
if (asc(substr(a,i,1))>=65 and asc(substr(a,i,1))<=90) or (asc(substr(a,i,1))>=97 and asc(substr(a,i,1))<=122)
zifu=zifu+1
else
hanzi=hanzi+1
endif
endfor
?"该段文本包含英文字符"+alltrim(str(zifu))+"个。"
?"该段文本包含中文字符"+alltrim(str(hanzi/2))+"个。"

例如输入:
我A是B中C国D人
结果是:
该段文本包含英文字符4个。
该段文本包含中文字符5个。本回答被提问者和网友采纳
相似回答