Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
replace() funciton with multiple tests....
so basically I'm looking to do the following, which obv doesn't work...
Replace(string, Or("purge_", "dealdrop_"), "cor010_wcout") I've tried Replace(string, Array("purge_", "dealdrop_"), "cor010_wcout") which also doesn't work. since i'll never be in a situation where string will contain both purge_ and dealdrop_ I've gone the route of running the replace function twice as follows: tempstring = Replace(string, "purge_", "cor010_wcout") tempstring = Replace(string, "dealdrop_", "cor010_wcout") but there's Got to be a more elegant way than just trying to shove a square peg in a round hole with a big hammer... ideas? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
replace() funciton with multiple tests....
Hi Matthew,
Am Mon, 28 Nov 2016 15:53:19 -0800 (PST) schrieb Matthew Dyer: Replace(string, Or("purge_", "dealdrop_"), "cor010_wcout") I've tried Replace(string, Array("purge_", "dealdrop_"), "cor010_wcout") which also doesn't work. since i'll never be in a situation where string will contain both purge_ and dealdrop_ I've gone the route of running the replace function twice as follows: tempstring = Replace(string, "purge_", "cor010_wcout") tempstring = Replace(string, "dealdrop_", "cor010_wcout") you can nest to functions: tempstring = Replace(Replace(string, "purge_", "cor010_wcout"), "dealdrop_", "cor010_wcout") or you can do it with an array: varRep = Array("purge_", "dealdrop") For i = LBound(varRep) To UBound(varRep) tempstring = Replace(string, varRep(i), "cor010_wcout") Next Regards Claus B. -- Windows10 Office 2016 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
replace() funciton with multiple tests....
Hi,
Am Tue, 29 Nov 2016 01:08:10 +0100 schrieb Claus Busch: tempstring = Replace(Replace(string, "purge_", "cor010_wcout"), "dealdrop_", "cor010_wcout") or you can do it with an array: varRep = Array("purge_", "dealdrop_") For i = LBound(varRep) To UBound(varRep) tempstring = Replace(string, varRep(i), "cor010_wcout") Next or another suggestion with Regexp: Set re = CreateObject("vbscript.Regexp") ptrn = "purge_|dealdrop_" re.Pattern = ptrn re.IgnoreCase = False re.Global = True tempstr = re.Replace(string, "cor010_wcout") Regards Claus B. -- Windows10 Office 2016 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
replace() funciton with multiple tests....
In message of Tue, 29 Nov 2016 01:08:10 in
microsoft.public.excel.programming, Claus Busch <claus_busch@t- online.de writes Hi Matthew, Am Mon, 28 Nov 2016 15:53:19 -0800 (PST) schrieb Matthew Dyer: Replace(string, Or("purge_", "dealdrop_"), "cor010_wcout") I've tried Replace(string, Array("purge_", "dealdrop_"), "cor010_wcout") which also doesn't work. since i'll never be in a situation where string will contain both purge_ and dealdrop_ I've gone the route of running the replace function twice as follows: tempstring = Replace(string, "purge_", "cor010_wcout") tempstring = Replace(string, "dealdrop_", "cor010_wcout") you can nest to functions: tempstring = Replace(Replace(string, "purge_", "cor010_wcout"), "dealdrop_", "cor010_wcout") or you can do it with an array: varRep = Array("purge_", "dealdrop") For i = LBound(varRep) To UBound(varRep) tempstring = Replace(string, varRep(i), "cor010_wcout") Next As usual, Claus pushes my knowledge. I am NOT suggesting this for Matthew, but I can strongly recommend Regular Expressions for more complicated replacements than this. I might (I wouldn't) write string = getsub("(?:purge\|dealdrop)_", "cor010_wcout"). I have a module to access RE. In that I have: Option Explicit Public RE As RegExp ' Needs Tools/References/Microsoft Vbscript Regular Expressions 1.0 or 5.5 Private Sub EnsureREInitialized() If RE Is Nothing Then Set RE = CreateObject("VBScript.Regexp") RE.Global = True End If End Sub .... Public Function GetSub(ByVal From As String, ByVal p As String, ByVal Part As String) As String EnsureREInitialized RE.Pattern = p GetSub = RE.Replace(From, Part) End Function -- Walter Briscoe |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
If AND/OR funciton with multiple criteria | Excel Worksheet Functions | |||
Multiple Conditional tests with Sumproduct | Excel Worksheet Functions | |||
Countif Using Multiple Logic Tests | Excel Worksheet Functions | |||
Multiple tests for a condition | Excel Programming | |||
Average a group of tests for grade, some tests not taken by all. | Excel Discussion (Misc queries) |