
用vb编写一个用户自定义函数用于计算字符串s中的所有数字之和。 例如s="a?23bd /"时,和为5。
2014-12-19
展开全部
Function qiuhe(s) As Integer
Dim i As Integer, j As Integer, sum As Integer
i = Len(s)
sum = 0
For j = 1 To i
Dim c
c = Mid(s, j, 1)
c = Asc(c)
If (c >= 48 And c <= 57) Then
sum = sum + Int(Chr(c))
End If
Next
qiuhe = sum
End Function
Dim i As Integer, j As Integer, sum As Integer
i = Len(s)
sum = 0
For j = 1 To i
Dim c
c = Mid(s, j, 1)
c = Asc(c)
If (c >= 48 And c <= 57) Then
sum = sum + Int(Chr(c))
End If
Next
qiuhe = sum
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询