473,387 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

String pattern matching with the VBA Replace function?

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
Jan 31 '06 #1
4 22969
Lauren Wilson <no****@nospam.com> wrote in
news:48********************************@4ax.com:
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

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.
--
Lyle Fairfield
Jan 31 '06 #2
On Tue, 31 Jan 2006 19:39:02 GMT, Lyle Fairfield
<ly***********@aim.com> wrote:
Lauren Wilson <no****@nospam.com> wrote in
news:48********************************@4ax.com :
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

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.

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.

Jan 31 '06 #3
rkc
Lyle Fairfield wrote:
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.


Not to mention any part of the string before the optional start position
is dropped.
Feb 1 '06 #4

WOW Lyle! It worked perfectly with ZERO modification. You are
awesome. Thanks a bunch.

-- LW


On Tue, 31 Jan 2006 19:39:02 GMT, Lyle Fairfield
<ly***********@aim.com> wrote:
Lauren Wilson <no****@nospam.com> wrote in
news:48********************************@4ax.com :
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


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.

Feb 1 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Thomas Mlynarczyk | last post by:
Which is the simplest way to remove all whitespace from a string? Is there a simpler method than a regex replace? Or how can I tell a regex pattern to ignore all whitespace in my subject string?...
9
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # Matching string patterns # # Sometimes you want to know if a string is of # particular pattern. Let's say in your website # you have converted all images...
13
by: dimitris67 | last post by:
How can I replace an occurence of p(a string) in an other string(s) with np(new string).. char* replace _pattern(char *s,char *p,char *np) PLEASE HELP ME!!!!!
19
by: Paul | last post by:
hi, there, for example, char *mystr="##this is##a examp#le"; I want to replace all the "##" in mystr with "****". How can I do this? I checked all the string functions in C, but did not...
17
by: Tom | last post by:
Is there such a thing as a CONTAINS for a string variable in VB.NET? For instance, I want to do something like the following: If strTest Contains ("A","B", "C") Then Debug.WriteLine("Found...
5
by: olaufr | last post by:
Hi, I'd need to perform simple pattern matching within a string using a list of possible patterns. For example, I want to know if the substring starting at position n matches any of the string I...
18
by: Umesh | last post by:
Do you have any answer to it? thx.
0
NeoPa
by: NeoPa | last post by:
ANSI-89 v ANSI-92 Before we get into all the various types of pattern matching that can be used, there are two ANSI standards used for the main types of wildcard matching (matching zero or more...
11
by: tech | last post by:
Hi, I need a function to specify a match pattern including using wildcard characters as below to find chars in a std::string. The match pattern can contain the wildcard characters "*" and "?",...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.