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 - rat() return rightmost position of a substring in string http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 rat()               Return rightmost position of a substring in string
------------------------------------------------------------------------------
 Declaration
   string.hdr

 Syntax
   func uint rat extern
   param const char cSearch, ;
         const char cSource

 Arguments
   cSearch is the string to search for.

   cSource is the string to scan.

 Return
   Position of the last substring occurrence.

 Description
   The rat() function returns the relative position of the first occurrence
   of cSearch within cSource starting from the rightmost character
   of cSource. If no match is found, a zero is returned. The first
   character in cSource is considered to be position one.

 Example
   #define EXAMPLE_STRING
   #include example.hdr

   func char ExtBak
   param const char cString
   // Change a file extension to become .bak
   vardef
      char cBak
      uint uDot
   enddef
   uDot := rat( ".", cString )               // search for dot in input string
   if uDot                                   // if dot found
      cBak := substr( cString, 1, uDot ) + "bak" // exchange extension
   else                                      // if no dot found
      cBak := cString + ".bak"               // append extension
   endif
   return( cBak )
   endfunc
   
   proc Test_rat
   ? ExtBak( "file" )
   ? ExtBak( "test.prg" )
   endproc

   proc main
   Test_rat()
   endproc

See Also: at()

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