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:


break on
 
'Replace all occurrences:' ?
; StringReplace('string with another string in the string', 'strong', 'STRONG') ? 
StringReplace('string with another string in the string', 'string', 'STRING') ?
StringReplace('string with another string in the string text', 'string', 'STRING') ?
StringReplace('text string with another string in the string text', 'string', 'STRING') ?
?
'Replace all occurrences, starting with the second:' ?
StringReplace('string with another string in the string', 'string', 'STRING', 2) ?
StringReplace('string with another string in the string text', 'string', 'STRING', 2) ?
StringReplace('text string with another string in the string text', 'string', 'STRING', 2) ?
?
'Replace only the second occurrence:' ?
StringReplace('string with another string in the string', 'string', 'STRING', 2, 1) ?
StringReplace('string with another string in the string text', 'string', 'STRING', 2, 1) ?
StringReplace('text string with another string in the string text', 'string', 'STRING', 2, 1) ?
 
 
 
 
 
Function StringReplace($_Source, $_S1, $_S2, Optional $_Start, Optional $_Count)
 
  Dim $_Case						; current CASE setting 
  Dim $_aSource						; array of source string components 
  Dim $_I						; index pointer 
  Dim $_Min, $_Max					; min and max process values 
 
  $_Case = SetOption('CaseSensitivity', 'On')		; insure case-specific matching 
 
  $_aSource = Split($_Source, $_S1)			; break source sting into array 
  $_Min = 0						; Start processing here 
  $_Max = UBound($_aSource)				; end processing here 
  $_Start = IIf($_Start, $_Start - 1, 0)		; make the supplied start value 0-based 
 
  ; define the Count value to ALL if not specified 
  $_Count = IIf($_Count, $_Count, $_Max)
  If $_Count > $_Max
    $_Count = $_Max					; don't allow a greater count than elements 
  EndIf
 
  ; handle situations where the first element is a replacement value 
  If $_aSource[0] = ''
    If $_Start = 0 And $_Count				; see if we should replace based on start and count 
      $StringReplace = $StringReplace + $_S2		; REPLACE! 
      $_Count = $_Count - 1				; reduce the count 
    Else
      $StringReplace = $StringReplace + $_S1		; original text - no replacement 
    EndIf
    $_Min = 1						; skip the first element in the loop 
  EndIf
 
  For $_I = $_Min to $_Max
    $StringReplace = $StringReplace + $_aSource[$_I]	; add original text component 
    If $_I < $_Max And $_aSource[$_I]			; handle replacable last element 
      If $_I >= $_Start And $_Count			; see if we should replace based on start and count 
        $StringReplace = $StringReplace + $_S2		; REPLACE! 
        $_Count = $_Count - 1				; reduce count 
      Else
        $StringReplace = $StringReplace + $_S1		; original text, no replacement 
      EndIf
    EndIf
  Next
 
  $_Case = SetOption('CaseSensitivity', $_Case)		; restore original value 
 
  Exit 0
 
EndFunction
 
 
 
Just my opinion..

Glenn

_________________________
Actually I am a Rocket Scientist! \:D