设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1467|回复: 2
打印 上一主题 下一主题

[模块/函数] 一个字符在另一字符串中出现次数最多计数函数

[复制链接]
跳转到指定楼层
1#
发表于 2012-3-21 10:15:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
这是我碰到的一个问题,后来找老师写的一个函数,感觉这个函数在很多方面都能用上,所以和大家一起分享。

Public Function GetDisplayMax(tcWords As String, tcWord As String) As Integer
    Dim i As Integer, m As Integer
    Dim s As String
    Dim c As String
    Dim n As Integer
    Dim l As String
    Dim intMaxCount As Integer
    s = tcWords
    m = Len(s)
   
    For i = 1 To m
        s = Mid(tcWords, i, m - i + 1)
        c = Left(s, Len(tcWord))
        'Debug.Print i, s, c
        
        If l <> c Then
            n = 0
        End If
        
        If c = tcWord Then
            i = i + Len(tcWord) - 1
            n = n + 1
            'Debug.Print i, n & "个"
        End If
        
        If n > intMaxCount Then intMaxCount = n   
        l = c
    Next i
    GetDisplayMax = intMaxCount
End Function
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2012-3-21 11:00:35 | 只看该作者
谢谢分享!
3#
发表于 2012-3-21 14:08:28 | 只看该作者
可以啊,呵呵基本全面的应用了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-10 18:59 , Processed in 0.093757 second(s), 26 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表