Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / January 2006

Tip: Looking for answers? Try searching our database.

String pattern matching with the VBA Replace function?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lauren Wilson - 31 Jan 2006 18:12 GMT
Hi folks,

We have a need to replace sub strings in certain message text.  We use
the Office Assistant to display help and often use the imbedded
formatting commands.  Those of you who have used them know they look
like this: "{cf 5}" or "{cf 0}" or "{ul 1}" or "{ul 0}", etc.  The
commonality they have is that they are always 6 charters long and
always begin and end with curly brackets.

This all works great if the user is running the retail version of
Access.  Unfortunately, some of our users run Access Runtime -- in
which case the code simply writes the same message text (including the
imbedded formatting strings) to a standard form window.  Of course, we
do this because. for some inexplicable reason, Microsoft will not
include Office Assistant functionality when an Access app is running
with Access Runtime.

So, we need to pre-process the message text for Runtime users and
remove all of the formatting strings.  Here is what we have tried:

lblTxt1 = Replace(lblTxt1, "{", "", , 6, vbBinaryCompare)

OR,

lblTxt1 = Replace(lblTxt1, "{", "", , 6, vbTextCompare)

OR,

lblTxt1 = Replace(lblTxt1, "{????}")

NONE of these approaches work.  Is there any way to use pattern
matching in combination with the Replace function?

I am praying that I won't be forced to use brute force Instr functions
to remove these formatting strings at runtime.

Any suggestions?

Thanks,

-- LW
Lyle Fairfield - 31 Jan 2006 19:39 GMT
> Hi folks,
>
[quoted text clipped - 37 lines]
>
> -- LW

I know you never use anything I suggest Lauren but, perhaps, this will
help someone else who comes upon this thread.

I have a function I use to strip HTML tags from text:

Public Function StripHTMLTags( _
   ByVal HTML As String) As String
   Dim a() As String
   Dim v As Variant
   a() = Split(HTML, "<")
   For Each v In a
       StripHTMLTags = StripHTMLTags & Mid$(v, InStr(v, ">") + 1)
   Next v
End Function

It's easily revised to do what I !!!!think!!!! you want to do:
Public Function StripOAFormattingCommands( _
   ByVal OAString As String) As String
   Dim a() As String
   Dim v As Variant
   a() = Split(OAString, "{")
   For Each v In a
       StripOAFormattingCommands = StripOAFormattingCommands & Mid$(v,
InStr(v, "}") + 1)
   Next v
End Function

When applied to your sentence
> Those of you who have used them know they look like this: "{cf 5}" or
> "{cf 0}" or "{ul 1}" or "{ul 0}", etc.
StripOAFormattingCommands returns
Those of you who have used them know they look like this: "" or "" or ""
or "", etc.
Perhaps, one will want to add something  to remove the [""]'s.

BTW, the fourth parameter of the Replace Function specifies the character
at which to begin the Replace, not the number of characters to be
replaced:

start
Optional. Position within expression where substring search is to begin.
If omitted, 1 is assumed.

Signature

Lyle Fairfield

Lauren Wilson - 31 Jan 2006 21:09 GMT
>> Hi folks,
>>
[quoted text clipped - 39 lines]
>
>I know you never use anything I suggest Lauren

I don't?  Lyle, I'm hurt that you think I would be so callous.  At the
moment I don't KNOW if I have or have not used any of your
suggestions, but I ALWAYS appreciate the efforts of you and others who
post such helpful things here.   The fact is that I learn new things
from many posts whether or not I end up using the exact technique
described in one. Please Lyle, never assume you are not appreciated.

I will DEFINITELY give the code below a try.  Thanks very much.

>but, perhaps, this will
>help someone else who comes upon this thread.
[quoted text clipped - 38 lines]
>Optional. Position within expression where substring search is to begin.
>If omitted, 1 is assumed.
Lauren Wilson - 31 Jan 2006 23:23 GMT
WOW Lyle! It worked perfectly with ZERO modification.  You are
awesome.  Thanks a bunch.

-- LW

>> Hi folks,
>>
[quoted text clipped - 80 lines]
>Optional. Position within expression where substring search is to begin.
>If omitted, 1 is assumed.
rkc - 31 Jan 2006 23:36 GMT
> BTW, the fourth parameter of the Replace Function specifies the character
> at which to begin the Replace, not the number of characters to be
[quoted text clipped - 3 lines]
> Optional. Position within expression where substring search is to begin.
> If omitted, 1 is assumed.

Not to mention any part of the string before the optional start position
is dropped.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.