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

Regular expression to replace a pattern?

Status
Not open for further replies.

aimlion11yahoo

Instructor
Jul 20, 2006
42
US
Below is a selection of code I've highlighted.


Code:
Me._oRelease.PriceShipping = .Item("PriceShipping")
Me._oRelease.PriceTotal = .Item("PriceTotal")
Me._oRelease.PriceTotalItems = .Item("PriceTotalItems")
Me._oRelease.ReleaseGID = .Item("ReleaseGID")
Me._oRelease.ReleaseStatusTypeGID = .Item("ReleaseStatusTypeGID")
Me._oRelease.SalesTax = .item("SalesTax")
Me._oRelease.ShipDateEst = .item("ShipDateEst")
Me._oRelease.ShippingMethodGID = .item("ShippingMethodGID")
Me._oRelease.ShipToGID = .Items("ShipToGID")
Me._oRelease.SubTotal = .Item("SubTotal")


I want to find every pattern that begins with .Item and ends with GID").
Then I want to replace these patterns with a prefix of Func.CheckDBNull( and a suffixe of ).


Code:
Me._oRelease.PriceShipping = .Item("PriceShipping")
Me._oRelease.PriceTotal = .Item("PriceTotal")
Me._oRelease.PriceTotalItems = .Item("PriceTotalItems")
Me._oRelease.ReleaseGID = [COLOR=red]Func.CheckDBNull([/color].Item("ReleaseGID")[COLOR=red])[/color]
Me._oRelease.ReleaseStatusTypeGID = [COLOR=red]Func.CheckDBNull([/color].Item("ReleaseStatusTypeGID")[COLOR=red])[/color]
Me._oRelease.SalesTax = .item("SalesTax")
Me._oRelease.ShipDateEst = .item("ShipDateEst")
Me._oRelease.ShippingMethodGID = [COLOR=red]Func.CheckDBNull([/color].item("ShippingMethodGID")[COLOR=red])[/color]
Me._oRelease.ShipToGID = [COLOR=red]Func.CheckDBNull([/color].Items("ShipToGID")[COLOR=red])[/color]
Me._oRelease.SubTotal = .Item("SubTotal")
 
Look up MatchEvaluator under help on RegEx. That will do exactly what you need.


Hope this helps.

[vampire][bat]
 
This was actually a little fiddlier than I had first thought, so:

The RegEx pattern - note I've only shown the actual pattern and as it includes the " symbol you will need to handle that yourself:

[tt]
\.Item?\(\".+(GID\"\))
[/tt]

Although the pattern could possibly be simplified, doing so would make the MatchEvaluator a bit more complicated.

The MatchEvaluator (assuming input param is called [tt]m[/tt]):

[tt]
Return "Func.CheckDBNull(" + m.ToString() + ")"
[/tt]


Hope this helps.


[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top