End Function
----------------------------------------
没有专用函数能解决,只有编一个小代码了。
如果你要找的字符是A,要搜索的字串变量是b
for i=1 to len(b)'逐个循环变量B中字符
if instr(i,b,"A")>0 then j=j+1'如果找到一个就将计数+1并从下一位开始继续查
next
取得的j变量就是你的要求。
*********************************************
vb中,求一个字符串在另一个字符串中第二次出现的位置,用什么函数?不是求最后一次出现位置,也不是第一次出现位置。
Instr and InstrRev函数都似乎无法满足要求。
Dim nPos As Long, strSource As String, strFind As String
strSource = "ABCDABCE"
strFind = "AB"
nPos = InStr(1, strSource, strFind)
If nPos > 0 Then
nPos = InStr(nPos + Len(strFind), strSource, strFind)
End If
Print "第二次出现位置是:" & nPos
////////////////////////////
str=text1.text '假定测试的字符来自文本框
n=len(str) '计算字符串的总长度
numa=0 '用numa变量存储字母a的个数
for i= 1 to n ’从第一个位置开始到最后一个字符挨个判断
c=mid(str,i,1) '每次从字符串中去一个字符
if c="a" then numa=numa+1 '如果取出来的的当前字符是a,就记一个数
next i
print numa '输出最后的统计结果
联系客服