Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wild character in REPLACE function

Status
Not open for further replies.

MikeCDPQ

Technical User
Joined
Sep 11, 2003
Messages
173
Location
CA
Can one use a wild character in a replace function.

example: DC=123.

DC= is constant but 123 could be any number. I need to replace DC=??? by whatever.

ex: ChangeString = replace(Expression,"DC=" & variable,"whatever")

I have been trying different combination but nothing seems to work.

Thanks for any suggestion.

Mike
 
Look like a job for Regular Expressions. Do a search for RegExp and Replace



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
I have been reading about this RegExp and it seems awfully complicated for what I want to do.

I simply want to replace "DC=" plus the next 3 characters to the right by empty string

the string could hardly ever be any longer than 30 to 40 characters.

Something like: Replace(Str,DC=???,"")

Thanks
 
You could use Instr function to find your search string and then use the Mid$ function to pick up the new string. (just quickly typed in Imm mode, so no Dim or checking)

a= "asdffghxxx123vbnjhytg"
b=instr(1,a,"xxx")
c=mid$(a,1,b-1) & mid$(a,b+6)
?c
asdffghvbnjhytg


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Regular Expressions awfully complicated? Pah! (as regular readers will expect to me to say :-))
Code:
[blue]Private Function DCReplace(strSource As String, Optional strReplacement As String = "") As String
    With CreateObject("vbscript.regexp")
        .Pattern = "DC=\d{3}"
        DCReplace = .Replace(strSource, strReplacement)
    End With
End Function
[/blue]
 
Thanks for your help Johnm and Strongm.

Johnm, your solution worked beautifully after a bit of tweaking to accomodate my script.

Strongm, I still gave your solution a try but it did not work. I know that it should and that I am doing something wrong. I will get back to your solution when I have a bit more time to devote to the understanding of RegExp :-)

Thanks a lot to both of you!

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top