Re: Replace Space
- From: Bee <Bee@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 15 Aug 2009 18:49:01 -0700
Thanks for the quick reply.
I will take it all into serious consideration.
I thought it would be fun to mess with RegEx.
So far, I have some working code to do simple searches.
I am also trying the Like Search provided in a previous post.
Not much hair left here either ... so I wear a hat.
If you ever see a guy with blurry eyes and a hat ... that's me.
"Larry Serflaten" wrote:
.
"Bee" <Bee@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote
I am looking for a speedier way to do the following in VB6 rather than coding
up a slow character by character search and replace.
In a possibly large string (user input) I need to find and replace each
space with
space-characters-space.
However, within the string there are areas that may be defined with spaces
that must not be touched. They always have the format { } e.g.
{sometext space someothertext}
or
{sometext} ' no space
Is there an fast way to do this? Regex ?
Not too familiar with Regex.
As others have said, you would probably do better with your own code.
The trick to faster string manipulations is to avoid concatenation as you
work through your text. In other words, allocate enough memory for your
output buffer in one shot, and then transfer over the parts you need.
The example code below replaces the space character with   without
touching spaces within the curly braces. See if that helps you get started....
LFS
Option Explicit
Private Sub Form_Load()
Debug.Print Custom("Now is the time for {all good men} to come to the aid of their country.")
End Sub
Function Custom(Original As String) As String
Dim work As String, itm As String
Dim src As Long, dst As Long, active As Boolean
Const rpl = "  "
Const tagStart = "{", tagEnd = "}"
work = String$(Len(Original) * Len(rpl), 0) ' pick a suitable amount....
dst = 1
active = True
For src = 1 To Len(Original)
itm = Mid$(Original, src, 1)
Mid(work, dst, 1) = itm
dst = dst + 1
Select Case itm
Case " "
If active Then
Mid(work, dst) = rpl
dst = dst + Len(rpl)
End If
Case tagStart
active = False
Case tagEnd
active = True
End Select
Next
Custom = Left$(work, dst - 1)
End Function
- References:
- Replace Space
- From: Bee
- Re: Replace Space
- From: Larry Serflaten
- Replace Space
- Prev by Date: Re: Replace Space
- Next by Date: Re: Replace Space
- Previous by thread: Re: Replace Space
- Next by thread: Re: Replace Space
- Index(es):
Relevant Pages
|