VBA 函数 统计字符串中字母的个数

Function CountItems(text As String, delimeter As String) As Long

Dim arr() As String  '定义一个数组arr(),盛装字符串
arr = Split(text, delimeter)  '把Split函数拆分出来的数据,装进arr数组;

CountItems = UBound(arr) + 1    '统计字符串个数

End Function

  

  

其他地方可以调用这个函数,例如:

Sub dfd()

Dim str As String
str = "iPhone, iPad, iWatch, iPaid"

j = CountItems(str, ",")     '用逗号拆分字符串

Debug.Print j

End Sub

  

posted @ 2022-06-29 14:59  uuxyz  阅读(717)  评论(0)    收藏  举报
联系我