Office中国论坛/Access中国论坛
标题:
去掉任何指定的头尾字符通用函数
[打印本页]
作者:
tmtony
时间:
2005-7-17 07:38
标题:
去掉任何指定的头尾字符通用函数
功能类似 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
作者:
软件下载
时间:
2005-7-17 09:24
版主,你会不会写文本处理器的插件?(软件名:EMEDITOR,国外的,有汉化版,网上有很多插件下载),我很需要一个设置字体格式的插件,你会做吗?
作者:
tmtony
时间:
2005-7-17 21:59
呵呵,这个我没有做过,估计原理类似addin加载项, 用VB可以实现这样的功能, 实际上也类似C/S , 预留一个接口. 当然用ACCESS也可间接实现,但的确不是ACCESS的强项,而且也没有太大的必要哦. 如果仅是设置字体格式,可以使用API来实现
作者:
chaojianan
时间:
2009-10-25 21:01
谢谢版主分享。
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3