scripting@wanadoo.nl




InString()

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
9 January 2002 InString()
AuthorScriptLogic Corporation
Action Scans a string for the presence of a second string.
SyntaxInString (ExpC1, ExpC2, [ExpN]) 
Parameters
  • ExpC1 (Required / String) the string to search in.
  • ExpC2 (Required / String) the string to search for.
  • ExpN (Optional / Numeric) If included, InString() searches for the ExpNth occurrence of ExpC2 in ExpC1. By default, InString() searches for the first occurrence of ExpC2 (ExpN = 1). Including ExpN lets you search for additional occurrences of ExpC2 in ExpC1. 
  • RemarksIdentical to KiXtart's built-in InStr() function, except that this function support a third, optional parameter for the occurrence.
    Still need to write an InStringRev function, which would work same way, but from right to left. 
    ReturnsReturns the beginning numeric position of the first occurrence of a character expression within another character expression, counting from the leftmost character. If ExpC2 is not found within ExpC1, or if the ExpNth occurrence is not found, a 0 is returned. 
    DependenciesNone. 
    Examples
    $String1='abcdabcdabcd'
    $String2='abc'
    $result=InString($String1,$String2) ;returns 1
    $result=InString($String1,$String2,2) ;returns 5
    $result=InString($String1,$String2,3) ;returns 9
    $result=InString($String1,$String2,4) ;returns 0
    
     
    Source
    FUNCTION InString ($expc1, $expc2, OPTIONAL $expn)
      ; Similar to KiXtart's built-in INSTR() function, except that
      ; it offers a third parameter $ExpN. If $ExpN is included,
      ; instring() searches for the $ExpNth occurrence of $ExpC2
      ; in $ExpC1 and returns the location at which the $ExpNth
      ; occurrence of $ExpC2 starts.
    
      DIM $count, $origlenexpc1, $origlenexpc2, $loc
      $origlenexpc1=Len($expc1)
      $lenexpc2=Len($expc2)
      IF $origlenexpc1 < 1 OR $lenexpc2 < 1 ; need valid params.
        $instring=-1
        RETURN
      ENDIF
      $expn=0+$expn
      FOR $x = 1 TO $expn-1
        $loc=InStr($expc1,$expc2)
        IF $loc ; found
          $expc1=Substr($expc1,$loc+$lenexpc2,$origlenexpc1)
        ENDIF
      NEXT
      $loc=InStr($expc1,$expc2)
      IF $loc
        $instring=$origlenexpc1-Len($expc1)+$loc
      ELSE
        $instring=0
      ENDIF
    ENDFUNCTION ; - InString -
     
      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