FT_AT2

FT_AT2()
 Find position of the nth occurrence of a substring

 Syntax

      FT_AT2( <cSearch>, <cTarget> [, <nOccurs> [, <lCaseSens> ] ] ) -> nPos

 Arguments

     <cSearch> is the character substring to search for.

     <cTarget> is the character string to search.

     <nOccurs> is the occurrence of cSearch to look for,
                defaults to 1.

     <lCaseSens> is a logical value denoting case sensitivity.
                If .F., then search is NOT sensitive to case,
                defaults to .T.

 Returns

     The position of the nth occurrence of a substring

 Description

     This function will find the nth occurrence of a substring
     within a string.

 Examples

     cSearch := "t"
     cTarget := "This is the day that the Lord has made."

     FT_AT2( cSearch, cTarget )            // Returns ( 9 )

     FT_AT2( cSearch, cTarget, 2 )         // Returns ( 17 )

     FT_AT2( cSearch, cTarget, 2, .F. )    // Returns ( 9 )

 Source: AT2.PRG

 Author: Ralph Oliver,  TRANSCOM SYSTEMS

See Also: FT_FINDITH()



 

Substring comparison

 $
 Substring comparison--binary                    (Relational)
------------------------------------------------------------------------------
 Syntax

     <cString1> $ <cString2>

 Type

     Character, memo

 Operands

     <cString1> is a character or memo value that is searched for in
     <cString2>.

     <cString2> is a character or memo value within which <cString1> is
     sought.

 Description

     The $ operator is a binary relational operator that performs a case-
     sensitive substring search and returns true (.T.) if <cString1> is found
     within <cString2>.

 Examples

     .  This example illustrates the case-sensitivity of the substring
        operator ($):

        ? "A" $ "ABC"            // Result: .T.
        ? "a" $ "ABC"            // Result: .F.

See Also: < <= <> = (equality) == > >=

Operator overloading

/*
Operator overloading

 Some operators overloaded by extending their functionalities.
"$" was an operator for "checking substring existence in a string" 

 For example :

 ? "A" $ "ABC" // Result: .T.
 ? "Z" $ "ABC" // Result: .F.

 Now, this operator can be used for arrays and hashs too, not only strings.

 See examples below.

 "=>" was a preprocessor operator with meaning "translate to : ...".

Now, this operator can be used as a <key> - <value> separator in Hashs
for define and / or assign <key> - <value> to Hashs.
See examples below.

 "[ ]" was Array element indicator (Special)
 "{ }" was Literal array and code block delimiters (Special)

Now, this indicators can be used for hashs too. 
See examples below.

"+=" is self-increment operator that can be used both numeric 
and string values.

 Such as :

 cTest := "This"
 cTest += " is" 
 ? cTest // This is

 nTest := 3
 nTest += 10
 ? nTest // 13

 Now, this operator can be used for adding elements to an existing hash;
 ( but no for arrays ! ).
 Note : Extended functionalities of $ and += operators depends xHB lib.
        So need this usages to xHB lib and xHB.ch.

 See examples below.

*/
#include "xhb.ch"
PROCEDURE Main()

 CLS

 aFruits := { "apple", "appricot", "cherry", "melon", "pear", "mulberry" }

 ? "aFruits", IF( "pear" $ aFruits, '', 'not ' ) + "contain pear"
 ? "aFruits", IF( "grapes" $ aFruits, '', 'not ' ) +"contain grapes"

 aComplex := ARRAY( 10 )
AEVAL( aComplex, { | x1, i1 | aComplex[ i1 ] := i1 } )

 aComplex[ 5 ] := DATE()
 aComplex[ 7 ] := .F.

 ?
 ? "aComplex", IF( 3 $ aComplex, '', 'not ' ) + "contain 3"
 ? "aComplex", IF( 13 $ aComplex, '', 'not ' ) + "contain 13"
 ? "aComplex", IF( .T. $ aComplex, '', 'not ' ) + "contain .T."
 ? "aComplex", IF( .F. $ aComplex, '', 'not ' ) + "contain .F."
hEmpty := { => }
 ?
 ? "hEmpty is a", VALTYPE( hEmpty ), "type variable have",;
 STR( LEN( hEmpty ), 1 ), "element and it's",;
 IF( EMPTY( hEmpty ), '', 'not' ), "Empty"
hCountries := { 'Argentina' => "Buenos Aires" }
 hCountries += { 'Brasil' => "Brasilia" }
 hCountries += { 'Chile' => "Santiago" }
 hCountries += { 'Mexico' => "Mexico City" }

 ?
 ? "hCountries is a", VALTYPE( hCountries ), "type variable have",;
 STR( LEN( hCountries ), 1 ), "elements and and it's",;
 IF( EMPTY( hCountries ), '', 'not' ), "Empty"
cCountry := NIL
 FOR EACH cCountry IN hCountries
 ? cCountry:__ENUMKEY(), "=>", cCountry:__ENUMVALUE()
 NEXT 

 hDays := { 'Days' => { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" } }

 ?
 ? "hDays", IF( 'Days' $ hDays, '', 'not ' ) + "contain Days" 
 ? "hDays", IF( "Mon" $ hDays, '', 'not ' ) + "contain Mon" 
 ? "hDays['Days']", IF( "Fri" $ hDays["Days"], '', 'not ' ) + "contain Fri"
hLanguages := { "EN" => "English" } +; 
 { "DE" => "Deutsche" } +; 
 { "ES" => "Español" } +; 
 { "FR" => "Français" } +; 
 { "IT" => "Italiano" } +; 
 { "PL" => "Polkski" } +; 
 { "PT" => "Português" } +; 
 { "RU" => "Russkî" } +; 
 { "TR" => "Türkçe" }

 ?
 ? "hLanguages is a", VALTYPE( hLanguages ), "type variable have",;
 STR( LEN( hLanguages ), 1 ), "elements and and it's",;
 IF( EMPTY( hLanguages ), '', 'not' ), "Empty"
cLanguage := NIL 
 FOR EACH cLanguage IN hLanguages
 ? cLanguage:__ENUMKEY(), "=>", cLanguage:__ENUMVALUE()
 NEXT 

 @ MAXROW(), 0 
 WAIT "EOF OprOLoad.prg"
RETURN // OprOLoad.Prg.Main()
OprOLoad

Data Type Terms

Character :

A special data type consisting of one or more values in the extended character set. Characters can be grouped together to form strings. The maximum size of a character string In Clipper language is 65,534 bytes.

In Clipper, a character data may include any character, including “control” or “unprintable” characters, that are ASCII code less than 32.

Note : Characters with ASCII code 9, 10 and 13 always treated as “white spaces”; this important with EMPTY() and xTRIM() functions.

See Also:  String

Code Block :

A special data type that refers to a piece of compiled program code. In a program, the source code that specifies the creation of a code block.

Data Type :

The category of a data value. A data type is distinguished by the set of allowable values for that type, the set of operators that can be applied, and the storage format used to represent these values. In Clipper language, the following data types are defined: character, numeric, date, logical, array, object, code block, and NIL. Program variables may contain values of any type. Database field variables are limited to character, numeric, date, logical, and a special type called memo which is treated the same as character.

Date Type :

A special data type consisting of digits to store year, month, and day values. Operations on date values are based on chronological values.

Integer :

A number with no decimal digits. Note that Clipper language does not provide a separate data type for integer values.

Literal :

A source code element interpreted literally (as encountered), and assumed to have no abstract meaning. Generally a constant.

See Also: Constant

Logical Type :

A special data type consisting of true (.T.) or false (.F.) values.

See Also: Condition

Memo Type :

A special database field type consisting of one or more characters in the extended character set. The maximum size of a memo field in Clipper language is 65,534 bytes. A memo field differs only from a character string by the fact it is stored in a separate memo (.DBT file) and the field length is variable-length.

See Also: Character String

NIL :

A special data type that has only one allowable value. The special value (NIL) is automatically assigned to all uninitialized variables except publics, and is also passed as a substitute when arguments are omitted in a procedure or function call.

Numeric Type :

A special data type consisting of values that indicate magnitude. Numeric values consist of digits between zero and nine, a sign, and a decimal point.

Objects :

An object is an instance of a class. Each object has one or more attributes (called instance variables) and a series of operations (methods) that execute when a message is sent to the object. The object’s instance variables can only be accessed or assigned by sending messages to the object. Objects are created by calling a special function associated with a class.

See Also: Classes, Instance Variables, Messages, Methods

String :

Generically, a value of type character. In source code, a series of characters enclosed in single or double quotes.

See Also : Character

Substring :

A string within a string, usually to be specified as an argument of a function or command.