2833_en-US
Find Replace ScriptI have a column that contains string. I want to search through the column for a substring and delete it. I could do this through the Find/Replace dialog, but I want to do it in a script. I tried: Munger(:STATE, 1, "RX_", ""); What I expected it to do: change every occurrence of "RX_xxxxx" to "xxxxx", but it does nothing. What am I doing wrong?Re: Find Replace ScriptTry to combine munger() with the foreachrow() function to loop through all the rows.
Re: Find Replace ScriptThe SUBSTITUTE function, when used with a string, will replace all occurrences of a substring within a string. I didn't realize that when used with a list it only works with exact matches of the string-to-replace.
z = "aaabbbccc";
b = substitute(z, "a", "x");
Results in:
"xxxbbbccc"
So, you could use the for each row method or loop over all rows and use the SUBSTITUTE function.Re: Find Replace ScriptI find the SUBSTITUTE function to be a lot easier than MUNGER.
There may be a "one-liner" way, but here's what I do:
Re: Find Replace ScriptThanks to PMroz and MS for your help. I've gone with MS's suggestion for now, but I'm wondering what the impact on runtime will be if I have a couple million rows to loop through.Re: Find Replace ScriptPMroz, thanks.
MS, is there a function that can be used to find the last occurrence (i.e. search right to left instead of left to right), or do I have to iterate through the string to find the last occurrence and modify the offset accordingly?Re: Find Replace ScriptThere is a "reverse" function (ex: reverse("abc") --> "cba") which might help. You would search for the reversed text occurring first in the reversed column value, replace it with the reversed replacement text and then reverse the resulting string. Don't know how that compares speedwise with iterating the forward search.
Comments
There are no comments yet