scripting@wanadoo.nl




StringReplace()

http://www.scriptlogic.com/kixtart/FunctionLibrary_FunctionList.aspx


actual FunctionLibrary list on 'Scriptlogic' site printer-friendly mirror of UDF topic on 'scripting@wanadoo.nl' site close
28 April 2002 StringReplace()
AuthorMichel 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.
SyntaxStringReplace (SourceString, StrToReplace, ReplacementStr) 
Parameters
  • SourceString (Required / String) The string in which you want to replace some subString.
  • StrToReplace (Required / String) The string you want to replace.
  • ReplacementStr (Optional / String) The string you want to replace with. 
  • RemarksThe function is case unaware. 
    ReturnsA String with all subStrings changed to a new subString. 
    DependenciesNone. 
    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 -
     
      original source of UDF topic. show actual FunctionLibrary list on Scriptlogic site close top
              printer-friendly mirror of UDF topic on scripting@wanadoo.nl site  




    Copyright © 2003 www.scriptlogic.com & scripting@wanadoo.nl - last updated on 20 May 2003


    Site Meter