最简单的方法是?(问题简单,过来看看)

lxxldd 2003-05-06 03:52:07
怎样求一个字符在另一字符串的位置,越简单越好
...全文
56 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
rainstormmaster 2003-05-06
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim str As String
str = "abcdaabcef"
Dim c As String
c = "1"
Dim temp As Variant
temp = Split(str, c)
Dim i As Integer 'i 为所求
i = UBound(temp)
Print i

End Sub

MyLf 2003-05-06
  • 打赏
  • 举报
回复
dim str1 as string,str2
str1 = "acbdbdad12d56d98cd"
str2="d"
MsgBox "d 在 " & str1 & " 中出现 " & UBound(Split(str1, "d")) & " 次"
拿棵草 2003-05-06
  • 打赏
  • 举报
回复
哎!上面的程序瞒好的,我又学会了一招!谢谢!
of123 2003-05-06
  • 打赏
  • 举报
回复
dim strTmp as string, str1, str2 as string
dim n as long

str1 = "acbdbdad12d56d98cd"
str2 = "d"
n = len(str1)
strTmp = replace(str1,str2,"")
msgbox str1 & " 在 " & str2 & " 中出现 " & n - len(strTmp) & " 次"
拿棵草 2003-05-06
  • 打赏
  • 举报
回复
dim str="abcdaabcef"
dim c="a"
dim CountNum as integer

for i=1 to len(str)
if mid(str,i,1)=a then
countnum=countnum+1
end if
next i
lxxldd 2003-05-06
  • 打赏
  • 举报
回复
不好意思,我写错了
不是位置,而是一个字符在另一个字符串的次数
qingming81 2003-05-06
  • 打赏
  • 举报
回复
如楼上的,instr(str,substr),你可以指定从什么地方搜索起(默认是从头开始)
叶帆 2003-05-06
  • 打赏
  • 举报
回复
instr(str,substr)

7,785

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧