|
|
|
| 28 April 2002 | StringReplace() |
| Author | Michel Sijmons, original by Jeff Shahan. |
| Action | The function replaces all subString occurrences in a String with another subString, original by Jeff Shahan, modified by Michel Sijmons to really replace strings. |
| Syntax | StringReplace (SourceString, StrToReplace, ReplacementStr) |
| Parameters | |
| Remarks | The function is case unaware. |
| Returns | A String with all subStrings changed to a new subString. |
| Dependencies | None. |
| Examples |
$dummy=MessageBox(StringReplace("Hello Earth!", "Earth", "World"), "test",,10)
Dim $NewString
$OldString = "There#Once#Was#A#Man"
? $OldString
$NewString = StringReplace($OldString ,"#","\")
? $NewString ; the String is now "There\Once\Was\A\Man"
$NewString = StringReplace($NewString ,"a","?")
? $NewString ; the String is now "There\Once\W?s\?\M?n"
|
| Source |
FUNCTION StringReplace ($sourcestring, $strtoreplace, OPTIONAL $replacementstr)
; /* The function replaces all subString occurrences in a String with another subString,
; * original by Jeff Shahan, modified by Michel Sijmons to really replace strings.
; */
DIM $srsrcstrlen
$srsrcstrlen=Len($sourcestring)
IF ($srsrcstrlen > 0) AND ($srsrcstrlen > Len($strtoreplace))
DIM $array, $element
$array=Split($sourcestring, $strtoreplace, -1)
FOR EACH $element IN $array
$stringreplace=$stringreplace+$element+$replacementstr
NEXT
$stringreplace=Substr($stringreplace, 1, Len($stringreplace)-Len($replacementstr))
ELSE
$stringreplace=$sourcestring
ENDIF
ENDFUNCTION ; - StringReplace -
|
|
|
|