Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - substr() extract a substring from a character string http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 substr()            Extract a substring from a character string
------------------------------------------------------------------------------
 Declaration
   string.hdr

 Syntax
   func char substr extern
   param const char cString, ;
         value uint uStart, ;
         value uint uLength

 Arguments
   cString is the character string to convert.

   uStart is the start position of the resulting substring.

   uLength is the length of the output substring.

 Return
   A substring of the input string.

 Description
   The substr() function returns a substring of cString starting at
   the uStartPos for uLength characters. The substr() function is 1 based.
   That is, the 1st character in cString starts at position 1.

 Example
   #define EXAMPLE_STRING
   #include example.hdr

   /*
   The Banner() function takes four parameters. The first is the row where
   you want the text displayed, passed as a uint. The second parameter is
   also a uint and represents the beginning column for the text to be
   displayed at. Parameter number three is the ending column, again as a
   uint. The fourth parameter is the actual text to display. Banner() makes
   a call to swapcolors(), thus ensuring the text will use the currently
   defined colors. Banner() also returns the keystroke used to exit as a
   uint.
   */
   
   func uint Banner
   param value uint uRow, ;
         value uint uColStart, ;
         value uint uColEnd, ;
         value char cText
   vardef
      char    cHold
      uint    uMsgWidth
      uint    uCounter
      uint    uKey
      logical lCursor
   enddef
   uMsgWidth := ( uColEnd - uColStart ) + 1
   cHold     := space( uMsgWidth )
   uCounter  := 1
   uKey      := 0
   lCursor   := iscursor()
   cursor( .f. )
   swapcolors()
   do while ( uKey == 0 )
      cHold := substr( cHold, 2, ( uMsgWidth - 1 ) ) + ;
         substr( cText, uCounter, 1 )
      @ uRow, uColStart ?? cHold
      uCounter++
      if uCounter > len( cText )
         uCounter := 1
      endif
      uKey := waitkey( 150 )
   enddo
   cursor( lCursor )
   swapcolors()
   return( uKey )
   endfunc
   
   proc Test_substr
   vardef
      uint uKey
   enddef
   clear
   uKey := Banner( 5, 5, 74, ;
      "Press any key to exit the Banner() function..." + space( 20 ) )
   @ __max_row, 0 ?? "You pressed key number " + istr( uKey )
   endproc

   proc main
   Test_substr()
   endproc

See Also: left() right()

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