Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Ah - so the function logic is actually:
Code:
REPLACE - replace all occurrences of a substring with a new substring, starting at a specified character position.
REPLACE(InputString, OldString, NewString, Char_Offset)
Examples:
REPLACE("string with another string in it", "string", "STRING") ; "STRING with another STRING in it"
REPLACE("string with another string in it", "string", "STRING", 2) ; "string with another STRING in it"
REPLACE("string with another string in it", "string", "") ; " with another in it"
The original description text is a bit misleading. Glenn
_________________________ Actually I am a Rocket Scientist!
REPLACE("string with another string in it", "string", "STRING", 2) ; "STRING with another string in it"
I think Glenn is right, but the example is wrong. Should be "string with another STRING in it"
So is offset what we really want though? Seems like it might be either count(like Split and Join behavior), or skip(skip x number of results before the first replace).
TBH I'm really trying to think of a time when I would have ever used any of these when I am replacing.
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Right, missed that. I fixed the example in my post. I just copied/pasted Ruud's example at first.
I agree - Replace() without the offset just simplifies Join/Split. I can only think of a few times where I didn't need to make a global replacement.
Honestly, what would make the most sense to me is
Replace(Source, Substring1, Substring2, Offset, Count) which would search Source for Substring1, replacing it with Substring2, but only from the Offset position (or N'th occurrence) and only process Count replacements. Without a Count parameter, Offset doesn't seem to have as much value.
Here's a UDF with sample code that illustrates my thoughts using "N'th Occurrence" and "Count" optional parameters:
Just my opinion..
Glenn
_________________________ Actually I am a Rocket Scientist!
Registered: 1999-05-06
Posts: 391
Loc: Amsterdam, The Netherlands
Phhh... I just need to work on documenting these things better: the Replace function features not just an offset parameter, but also a count parameter. Exactly as you describe above. The manual has the correct description, it's the readme that's confusing.