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

 Syntax
   func uint at 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 first substring occurrence.

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

 Example
   #define EXAMPLE_STRING
   #include example.hdr

   proc Test_at
   vardef
      char cString
   enddef
   cString := "The Force Compiler"
   ? at( "T", cString )                             // prints 1
   ? at( "Force", cString )                         // prints 5
   ? at( "Clipper", cString )                       // prints 0 (not found)
   
   // split a string based on the position of a comma within it
   cString := "Flintstone, Fred"
   ? substr( cString, 1, at( ",", cString ) - 1 )   // prints last name
   ? substr( cString, at( ",", cString ) + 2, 255 ) // prints first name
   endproc

   proc main
   Test_at()
   endproc

See Also: $ rat()

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