一、问题描述:
老师,如何判断一串字符串中中文字个数?
二、解答:
这里需要要自定义函数:
Function CountZh(ByVal sZh As String) As Integer
Dim re As New RegExp
Dim matches As MatchCollection
re.Pattern = "[\u4e00-\u9fa5]"
re.Global = True
re.IgnoreCase = True
Set matches = re.Execute(sZh)
CountZh = matches.Count
Set re = Nothing
End Function
'请引用Microsoft VBScript Regular Express 5.5。
调用示例:
附 件:
点击下载此附件
图 示: