设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

[模块/函数] 去掉任何指定的头尾字符通用函数

[复制链接]

点击这里给我发消息

跳转到指定楼层
1#
发表于 2005-7-17 07:38:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
功能类似 LTRIM  RTRIM TRIM,但可去掉任何指定的头尾字符.

作者: r_cubed

摘抄: tmtony

Public Function GTrim(strInput As String, _

                             strCharToStrip As String, _

                             WhatToTrim As String) _

                     As String

                     

    ' This function is in addition to the Access functions

    ' LTrim and RTrim which trim off leading/trailing spaces from a field/string.

   

    ' The GTRIM function allows you to trim off ANY leading and/or trailing character

    ' OR "set of characters" (i.e. it is NOT restricted to only trimming off a

    ' SINGLE character at a time.

   

    ' Inputs:   Parameter 1:    String to be trimmed

    '           Parameter 2:    Leading/Trailing character/s to be trimmed

    '           Parameter 3:    L - Trim leading

    '                           R - Trim trailing

    '                           B - Trim leading AND trailing

   

    ' Examples: GTRIM("abcabcdefxyzabc","abc","B")  returns "defxyz"

    '           GTRIM("abcabcdefxyzab","abc","B")   returns "defxyzab"

    '           GTRIM("000321A","000","L")          returns "321A"

    '           GTRIM("00321A","000","L")           returns "00321A"        ** No change/no match

    '           GTRIM("  Hello World   "," ","B")   returns "Hello World"   ** Same as LTrim, RTrim

   

    ' Usage:    The function can be used anywhere that you can use ANY other function

    '

    ' ------------------------------------------------------------------------------------------



    Dim i As Integer

        

    If WhatToTrim = "L" _

      Or WhatToTrim = "B" Then

        ' Attempt to trim the leftside of the input string

        For i = 1 To Len(strInput) Step Len(strCharToStrip)

            If Mid$(strInput, i, Len(strCharToStrip)) <> strCharToStrip Then

                Exit For

            End If

        Next i

    End If

   

    If i < Len(strInput) Then

        strInput = Mid$(strInput, i)

    End If

   

    If WhatToTrim = "R" _

      Or WhatToTrim = "B" Then

        ' Attempt to trim the rightside of the input string

        i = Len(strInput) - Len(strCharToStrip) + 1

        For i = i To 1 Step -Len(strCharToStrip)

            If Mid$(strInput, i, Len(strCharToStrip)) <> strCharToStrip Then

                Exit For

            End If

        Next i

    End If

   

    If i >= 1 Then

        i = i + Len(strCharToStrip) - 1

        strInput = Mid$(strInput, 1, i)

    End If

   

    GTrim = strInput



End Function




分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2005-7-17 09:24:00 | 只看该作者
版主,你会不会写文本处理器的插件?(软件名:EMEDITOR,国外的,有汉化版,网上有很多插件下载),我很需要一个设置字体格式的插件,你会做吗?

点击这里给我发消息

3#
 楼主| 发表于 2005-7-17 21:59:00 | 只看该作者
呵呵,这个我没有做过,估计原理类似addin加载项, 用VB可以实现这样的功能, 实际上也类似C/S , 预留一个接口. 当然用ACCESS也可间接实现,但的确不是ACCESS的强项,而且也没有太大的必要哦. 如果仅是设置字体格式,可以使用API来实现
4#
发表于 2009-10-25 21:01:46 | 只看该作者
谢谢版主分享。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-9-22 23:25 , Processed in 0.103339 second(s), 28 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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