标题:[求助]如何自定义一个函数来实现查找指定字符串在另一字符串中第N个位置?
只看楼主
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
得分:0 
以下是引用slore在2007-9-11 17:49:10的发言:
没有测试效率,只是提供个另外的思路……

代码长度……

Private Function fncGetStrNum(InString As String, InSearch As String, InCount As Integer) As Long
Dim
TempStr As String
TempStr = Replace(InString, InSearch, "", 1, InCount - 1)
fncGetStrNum = InStr(TempStr, InSearch)
If fncGetStrNum <> 0 Then fncGetStrNum = fncGetStrNum + (InCount - 1) * Len(InSearch)
End Function

这个思路好,赞

以下是引用mohan123在2007-9-11 14:58:19的发言:

谢谢,但是我不明白“If Len(srchString) = 0 Then InStrL = -1: Exit Function”
为什么要赋值为-1。


随便的,一个Tag。你应当避免这种情况出现

2007-09-11 20:25



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-168953-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.161179 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved