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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wildcards in Replace Method 1

Status
Not open for further replies.

jordanking

Programmer
Sep 8, 2005
351
Is there a way to use wild cards in the replace method. The following did not work:

Code:
    strOutput = Replace(strOutput, "|***|", "", 1, 34, vbDatabaseCompare)


I have a string that is bascially the contents of a large array that is deliminated by |item|. Each item is an integer (not ascending or ordered, basically random) between 1 and 999 sandwiched by tilds(i.e: |1||12||87||5||126|) I want to be able to replace the first 32 occurances, skip over the next 52 and then replace the remaining occurances. The numbers 32 and 52 are user inputted values that I have captured. The entire string's length changes each time.

I can make the above code work when I put literal integers between the tilds but I don't know how to indicate any number between the tilds.

Thanks in advance.

jordan
 
You will probably need to use a Regular Expression to accomplish this.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I tried the regex, I found your comments in other threads an followed them to produce this.

Code:
  RgExp.Pattern = "\|[A-Z0-9][A-Z0-9][A-Z0-9]\|"

I put it in a loop 34 times and it removed the first 32 occurances of |*|

Code:
        For i = 1 To 34
        strOutput = RgExp.Replace(strOutput, "")
        Next

So i tried the following and it removed the first 34 occurances of |***|

Code:
  RgExp.Pattern = "\|[A-Z0-9][A-Z0-9][A-Z0-9]\|"

any ideas on how to replace the first 34 occurance whether the sandwiched interger is 1,2 or 3 integers long?

Thanks
 
never mind,

I found a website with a refrence list:

Code:
  RgExp.Pattern = "\|[0-9]\||\|[0-9][0-9]\||\|[0-9][0-9][0-9]\|"

did the job great!

Thanks for sending me in the right direction
 
I think I need more information. Here is what I think the situation is (on a small scale):

IN:
"|123||34||5||67||890|"

OUT:
"|***||**||5||67||***|"

In this example, we would want to replace the first 2 instances, skip 2 instances, then replace the rest. Is this an accurate (if small) example of wht you would like to see?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I worked it through a bit and came up with the following, thanks for the help

Code:
  RgExp1.Pattern = "\|[0-9]\||\|[0-9][0-9]\||\|[0-9][0-9][0-9]\|"
  RgExp2.Pattern = "(\|[0-9]\|)$|(\|[0-9][0-9]\|)$|(\|[0-9][0-9][0-9]\|)$"

I pass the string to RgExp1 and it removes the beginning and then I pass the string to RgExp2 controling the number of replacment with loops defined by user inputed values.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top