Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- CA-Clipper 5.2 . The Guide To CA-Clippe - <b>substr()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 SUBSTR()
 Extract a substring from a character string
------------------------------------------------------------------------------
 Syntax

     SUBSTR(<cString>, <nStart>, [<nCount>]) --> cSubstring

 Arguments

     <cString> is the character string from which to extract a substring.
     It can be up to 65,535 (64K) bytes, the maximum character string size in
     CA-Clipper.

     <nStart> is the starting position in <cString>.  If <nStart> is
     positive, it is relative to the leftmost character in <cString>.  If
     <nStart> is negative, it is relative to the rightmost character in the
     <cString>.

     <nCount> is the number of characters to extract.  If omitted, the
     substring begins at <nStart> and continues to the end of the string.  If
     <nCount> is greater than the number of characters from <nStart> to the
     end of <cString>, the extra is ignored.

 Returns

     SUBSTR() returns a character string.

 Description

     SUBSTR() is a character function that extracts a substring from another
     character string or memo field.  SUBSTR() is related to the LEFT() and
     RIGHT() functions which extract substrings beginning with leftmost and
     rightmost characters in <cString>, respectively.

     The SUBSTR(), RIGHT(), and LEFT() functions are often used with both the
     AT() and RAT() functions to locate either the first and/or the last
     position of a substring before extracting it.  They are also used to
     display or print only a portion of a character string.

 Examples

     .  These examples extract the first and last name from a
        variable:

        cName:= "Biff Styvesent"
        ? SUBSTR(cName, 1, 4)               // Result: Biff
        ? SUBSTR(cName, 6)                  // Result: Styvesent
        ? SUBSTR(cName, LEN(cName) + 2)     // Result: null string
        ? SUBSTR(cName, -9)                 // Result: Styvesent
        ? SUBSTR(cName, -9, 3)              // Result: Sty

     .  This example uses SUBSTR() with AT() and RAT() to create a
        user-defined function to extract a filename from a file
        specification:

        ? FileBase("C:\PRG\MYFILE.OBJ")      // Result: MYFILE.OBJ

        FUNCTION FileBase( cFile )
           LOCAL nPos
           IF (nPos := RAT("\", cFile)) != 0
              RETURN SUBSTR(cFile, nPos + 1)
           ELSEIF (nPos := AT(":", cFile)) != 0
              RETURN SUBSTR(cFile, nPos + 1)
           ELSE
              RETURN cFile
           ENDIF

 Files:  Library is CLIPPER.LIB.

See Also: AT() LEFT() RAT() RIGHT() STR()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson