Go to:  Davar site entry | Site contents | Site index | Personal Computer | PowerBASIC | Text bottom

TAILSTR$  PowerBASIC  Function

         

TAILSTR$ function evaluates to the string tail of its first parameter that starts right after the first entry of the delimiter, specified by the second parameter.  Special cases are taken care of (see function description below).  With the older and less sophisticated Microsoft BASICs I used to have also the HEADSTR$ function (similar to TAILSTR$), but PowerBASIC offers function EXTRACT$ that covers HEADSTR$ functionality.



 TAILSTR$  Source  Program                       Debugging program                   Debugging logout

      ' TAILSTR$(0.0)  Get Character String Tail                 09/23/1992-01/29/2010
      ' ------------------------------------------------------------------------------
      ' Copyright (C) 1992-2010 by Vladimir Veytsel                      www.davar.net

      ' Type -------------------------------------------------------------------------

      '    Function

      ' Description ------------------------------------------------------------------

      '    TAILSTR$ function returns string tail of its first argument delimited by
      '    first occurrence of its second argument.

      ' Parameters -------------------------------------------------------------------

      '    Strng$  - Character string
      '    Delim$  - Delimiting substring of string tail

      ' Value ------------------------------------------------------------------------

      '  - IF specified string is EMPTY,
      '       THEN returned string is EMPTY.

      '  - IF specified string is NOT empty        AND
      '       delimiting substring is either empty OR
      '       NOT found within specified string,
      '       THEN returned string is EMPTY.

      '  - IF specified string is NOT empty AND
      '       delimiter is found within specified string,
      '       THEN string tail is returned to the point of invocation.

      ' Notes ------------------------------------------------------------------------

      '  - First delimiter occurance from string left side delimits
      '    the returned substring.
      '  - If specified string ends with unique delimiter,
      '    then returned substring will be empty.
      '  - Returned substring never contains delimiter itself.

      ' Examples ---------------------------------------------------------------------

      '    TAILSTR$(""   ,"XYZ")=""
      '    TAILSTR$("ABC",""   )=""
      '    TAILSTR$("ABC","XYZ")=""
      '    TAILSTR$("ABC","A"  )="BC"
      '    TAILSTR$("ABC","AB" )="C"
      '    TAILSTR$("ABC","C"  )=""

      ' Start Function ---------------------------------------------------------------

           DEFINT A-Z  ' All defaulted variables are integer

           FUNCTION TAILSTR$(Strng$,Delim$)

      ' Form and Return Function Value to the Point of Invocation --------------------

           IF ((LEN(Strng$)=0)OR _
               (LEN(Delim$)=0)) THEN
              TAILSTR$=""
           ELSE
              I=INSTR(Strng$,Delim$)
              IF ((I=0)OR _
                  (I=LEN(Strng$)-LEN(Delim$)+1)) THEN
                 TAILSTR$=""
              ELSE
                 TAILSTR$=MID$(Strng$,I+LEN(Delim$))
              END IF
           END IF

      ' Finish Function --------------------------------------------------------------

           END FUNCTION
  
         

 TAILSTR$  Debugging  Program                       Source program                   Debugging logout

      ' TAILSTR$(0.0)  Get Character String Tail                 09/23/1992-01/29/2010
      ' ------------------------------------------------------------------------------

        #INCLUDE "TAILSTR"

        FUNCTION PBMAIN

        PRINT "TAILSTR$(0.0)  Get Character String Tail  "; DATE$;
        PRINT "  "; LEFT$(TIME$,5)
        PRINT STRING$(59,"-")
        PRINT

        PRINT "TAILSTR$(''   ,'XYZ')='"; _
               TAILSTR$(""   ,"XYZ"); "'"
        PRINT "TAILSTR$('ABC',''   )='"; _
               TAILSTR$("ABC",""   ); "'"
        PRINT "TAILSTR$('ABC','XYZ')='"; _
               TAILSTR$("ABC","XYZ"); "'"
        PRINT "TAILSTR$('ABC','A'  )='"; _
               TAILSTR$("ABC","A"  ); "'"
        PRINT "TAILSTR$('ABC','AB' )='"; _
               TAILSTR$("ABC","AB" ); "'"
        PRINT "TAILSTR$('ABC','C'  )='"; _
               TAILSTR$("ABC","C"  ); "'"

        END FUNCTION
  
         

 TAILSTR$  Debugging  Logout                     Source program                   Debugging program


   TAILSTR$(0.0)  Get Character String Tail  09-17-2016  18:24
   -----------------------------------------------------------

   TAILSTR$(''   ,'XYZ')=''
   TAILSTR$('ABC',''   )=''
   TAILSTR$('ABC','XYZ')=''
   TAILSTR$('ABC','A'  )='BC'
   TAILSTR$('ABC','AB' )='C'
   TAILSTR$('ABC','C'  )=''
        

         

View [and save] TAILSTR.BAS text       View [and save] ZTAILSTR.BAS text
(Use [Back] button or [Alt]+[CL] to return here from the viewed text)
Copyright © 19922010 by
Go to:  Davar site entry | Site contents | Site index | Personal Computer | PowerBASIC | Text top