SetAtLike()

SetAtLike()

Determine scan behaviour in some string functions

Syntax

      SetAtLike ([<nMode>] [, <[@]cWildcard>]) --> nOldMode

Arguments

[<nMode>] :

       CT_SetAtLike_EXACT -> characters are compared exactly

       CT_SetAtLike_WILDCARD -> characters are compared using a wildcard character

       The default value is CT_SetAtLike_EXACT.

[<[@]cWildcard>] determines the character that is subsequently used as a wildcard character for substring scanning. The default value is “?”.

NEW: If this parameter is passed by reference [@], the current wildcard character is stored in <cWildcard>.

Returns

nOldMode old (if nMode is a numeric value) or current state of the switch

Description

In the following CT3 functions, strings are compared on a character base:

ATADJUST(), ATNUM(), AFTERATNUM(), BEFOREATNUM(), ATREPL(), NUMAT(), STRDIFF()

With the SetAtLike function, one can determine when characters are considered to match within these functions. If CT_SetAtLike_WILDCARD is set (e.g. “?”), then “?” matches every other character.

<nMode> can be one of the following values that are defined in ct.ch

 
      Definition            | Value 
      ----------------------|------ 
      CT_SetAtLike_EXACT    |   0 
      CT_SetAtLike_WILDCARD |   1

Compliance

This function is fully CT3 compatible, but allows to pass the second parameter by reference so that the current wildcard character can be determined.

Platforms

All

Files

Source is ctstr.c, header is ct.ch, library is ct3.

AtNum()

AtNum()

Returns the start position of the nth occurence of a substring in a string

Syntax

      AtNum (<cStringToMatch>, <cString>, [<nCounter>],
             [<nIgnore>] ) --> nPosition

Arguments

<cStringToMatch> is the substring scanned for <cString> is the scanned string

[<nCounter>] determines how many occurences are of <cStringToMatch> in <cString> are searched Default: search last occurence

[<nIgnore>] determines how many character from the start should be ignored in the search Default: 0

Returns

<nPosition> the position of the <nCounter>th occurence of <cStringToMatch> in <cString>. If such an occurence does not exist, 0 is returned.

Description

This function scans <cString> for <cStringToMatch>. After the <nCounter>th match (or the last one, depending on the value of <nCounter>) has been found, the position of that match will be returned. If there aren’t enough matches or there is no last match, 0 will be returned. After a match has been found, the function continues to scan after that match if the CSETATMUPA() switch is turned off, with the second character of the matched substring otherwise. The function will also consider the settings of SETATLIKE().

Examples

      ? AtNum( "!", "What is the answer ? 4 ! 5 !" ) // -> 28
      ? AtNum( "!", "What is the answer ? 4 ! 5 ?" ) // -> 24

Tests

      AtNum( "..", "..This..is..a..test!" ) == 14
      AtNum( "..", "..This..is..a..test!", 2 ) == 7
      AtNum( "..", "..This..is..a..test!", 2, 2 ) == 11

Compliance

AtNum() is compatible with CT3’s AtNum().

Platforms

All

Files

Source is AtNum.c, library is libct.

Seealso

AtNum(), AfterAtNum(), CSETATMUPA(), SETATLIKE()

AfterAtNum()

AfterAtNum()

Returns string portion after nth occurence of substring

Syntax

      AfterAtNum( <cStringToMatch>, <cString>, [<nCounter>],
                  [<nIgnore>] ) --> cRestString

Arguments

<cStringToMatch> is the substring scanned for <cString> is the scanned string

[<nCounter>] determines how many occurences are of <cStringToMatch> in <cString> are searched Default: search last occurence

[<nIgnore>] determines how many character from the start should be ignored in the search Default: 0

Returns

<cRestString> the portion of <cString> after the <nCounter>th occurence of <cStringToMatch> in <cString> If such a rest does not exist, an empty string is returned.

Description

This function scans <cString> for <cStringToMatch>. After the <nCounter>th match (or the last one, depending on the value of <nCounter>) has been found, the portion of <cString> after that match will be returned. If there aren’t enough matches or the last match is identical to the end of <cString>, an empty string will be returned. After a match has been found, the function continues to scan after that match if the CSETATMUPA() switch is turned off, with the second character of the matched substring otherwise. The function will also consider the settings of SETATLIKE().

Examples

      ? AfterAtNum( "!", "What is the answer ? 4 ! 5 !" ) // -> ""
      ? AfterAtNum( "!", "What is the answer ? 4 ! 5 ?" ) // -> " 5 ?"
      <TODO: add some examples here with csetatmupa() and setatlike()>

Tests

      AfterAtNum( "..", "..This..is..a..test!" ) == "test!"
      AfterAtNum( "..", "..This..is..a..test!", 2 ) == "is..a..test!"
      AfterAtNum( "..", "..This..is..a..test!", 2, 2 ) == "a..test!"

Compliance

AfterAtNum() is compatible with CT3’s AfterAtNum().

Platforms

All

Files

Source is atnum.c, library is libct.

Seealso

ATNUM(), BEFORATNUM(), CSETATMUPA(), SETATLIKE()

CT_ATNUM

 ATNUM()
 Determines the starting position of a sequence within a string

 Syntax

     ATNUM(<cSearchFor>,<cString>,[<nCounter>],
        [<nIgnore>]) --> nPosition

 Arguments

     <cSearchFor>  Designates the expression for which the function
     searches.

     <cString>  Designates the character string to search.

     <nCounter>  Designates which occurrence of <cSearchFor> within
     <cString> is determined.  The default value is for the last occurrence
     of the search expression.

     <nIgnore>  Designates the number of characters that should be
     excluded from the search.  The default value is none (0).

 Returns

     The function returns the position where <cSearchFor> begins.  If no
     corresponding position can be determined, the function returns 0.

 Description

     ATNUM() determines the initial position of the nth (<nCounter>)
     occurrence of <cSearchFor> within the <cString>.  Additionally, the
     function takes into account the CSETATMUPA() setting, which causes
     differing results.

     ATNUM() searches from the left in order to determine the nth
     (<nCounter>) occurrence of the <cSearchFor>.  If CSETATMUPA() is off,
     the search continues after the last character of the sequence most
     recently located.  However, if the CSETATMUPA() is on, the search always
     continues after the first character in the most recently located
     sequence.

     If the <nIgnore> parameter is not specified, the function initiates the
     search with the first character of <cString>.  If the <nIgnore>
     parameter is specified, <nIgnore> characters are ignored from the start
     of the string and are excluded from the search.

 Notes

     .  If no value is specified for <nCounter>, the function
        determines the last occurrence of the <cSearchFor> sequence.

     .  When you implement SETATLIKE(), wildcard characters can be
        used within the search expression.

 Examples

     .  Search for the last occurrence:

        ? ATNUM("bc", "abcdeabc")               // Result: 7

     .  Search for the first occurrence:

        ? ATNUM("bc", "abcdeabc", 1)            // Result: 2

     .  Search for the first occurrence, excluding the first three
        characters:

        ? ATNUM("bc", "abcdeabc", 1, 3)         // Result: 7

     .  Determine the impact of CSETATMUPA() on a search for the last
        occurrence of "aa" in "aaa":

        CSETATMUPA(.F.)                         // Off
        ? ATNUM("aa", "aaa")                    // Result: 1

        CSETATMUPA(.T.)                         // On
        ? ATNUM("aa", "aaa")                    // Result: 2

See Also: CSETATMUPA() SETATLIKE()

 

Tools – String Manipulations

Introduction 
ADDASCII()   Adds a value to each ASCII code in a string
AFTERATNUM() Returns remainder of a string after nth appearance of sequence
ASCIISUM()   Finds sum of the ASCII values of all the characters of a string
ASCPOS()     Determines ASCII value of a character at a position in a string
ATADJUST()   Adjusts the beginning position of a sequence within a string
ATNUM()      Determines the starting position of a sequence within a string
ATREPL()     Searches for a sequence within a string and replaces it
ATTOKEN()    Finds the position of a token within a string
BEFORATNUM() Returns string segment before the nth occurrence of a sequence
CENTER()     Centers a string using pad characters
CHARADD()    Adds the corresponding ASCII codes of two strings
CHARAND()    Links corresponding ASCII codes of paired strings with AND
CHAREVEN()   Returns characters in the even positions of a string
CHARLIST()   Lists each character in a string
CHARMIRR()   Mirrors characters within a string
CHARMIX()    Mixes two strings together
CHARNOLIST() Lists the characters that do not appear in a string
CHARNOT()    Complements each character in a string
CHARODD()    Returns characters in the odd positions of a string
CHARONE()    Reduces adjoining duplicate characters in string to 1 character
CHARONLY()   Determines the common denominator between two strings
CHAROR()     Joins the corresponding ASCII code of paired strings with OR
CHARPACK()   Compresses (packs) a string
CHARRELA()   Correlates the character positions in paired strings
CHARRELREP() Replaces characters in a string depending on their correlation
CHARREM()    Removes particular characters from a string
CHARREPL()   Replaces certain characters with others
CHARSORT()   Sorts sequences within a string
CHARSPREAD() Expands a string at the tokens
CHARSWAP()   Exchanges all adjoining characters in a string
CHARUNPACK() Decompresses (unpacks) a string
CHARXOR()    Joins ASCII codes of paired strings with exclusive OR operation
CHECKSUM()   Calculates the checksum for a character string (algorithm)
COUNTLEFT()  Counts a particular character at the beginning of a string
COUNTRIGHT() Counts a particular character at the end of a string
CRYPT()      Encrypts and decrypts a string
CSETATMUPA() Determines setting of the multi-pass mode for ATXXX() functions
CSETREF()    Determines whether reference sensitive functions return a value
EXPAND()     Expands a string by inserting characters
JUSTLEFT()   Moves characters from the beginning to the end of a string
JUSTRIGHT()  Moves characters from the end of a string to the beginning
LIKE()       Compares character strings using wildcard characters
LTOC()       Converts a logical value into a character
MAXLINE()    Finds the longest line within a string
NUMAT()      Counts the number of occurrences of a sequence within a string
NUMLINE()    Determines the number of lines required for string output
NUMTOKEN()   Determines the number of tokens in a string
PADLEFT()    Pads a string on the left to a particular length
PADRIGHT()   Pads a string on the right to a particular length
POSALPHA()   Determines position of first alphabetic character in a string
POSCHAR()    Replaces individual character at particular position in string
POSDEL()     Deletes characters at a particular position in a string
POSDIFF()    Finds the first position from which two strings differ
POSEQUAL()   Finds the first position at which two strings are the same
POSINS()     Inserts characters at a particular position within a string
POSLOWER()   Finds the position of the first lower case alphabetic character
POSRANGE()   Determines position of first character in an ASCII code range
POSREPL()    Replaces one or more characters from a certain position
POSUPPER()   Finds the position of the first uppercase, alphabetic character
RANGEREM()   Deletes characters that are within a specified ASCII code range
RANGEREPL()  Replaces characters within a specified ASCII code range
REMALL()     Removes characters from the beginning and end of a string
REMLEFT()    Removes particular characters from the beginning of a string
REMRIGHT()   Removes particular characters at the end of a string
REPLALL()    Exchanges characters at the beginning and end of a string
REPLLEFT()   Exchanges particular characters at the beginning of a string
REPLRIGHT()  Exchanges particular characters at the end of a string
RESTTOKEN()  Recreates an incremental tokenizer environment
SAVETOKEN()  Saves the incremental tokenizer environment to a variable
SETATLIKE()  Provides an additional search mode for all AT functions
STRDIFF()    Finds similarity between two strings (Levenshtein Distance)
STRSWAP()    Interchanges two strings
TABEXPAND()  Converts tabs to spaces
TABPACK()    Converts spaces in tabs
TOKEN()      Selects the nth token from a string
TOKENAT()    Determines the most recent TOKENNEXT() position within a string
TOKENEND()   Determines if more tokens are available in TOKENNEXT()
TOKENINIT()  Initializes a string for TOKENNEXT()
TOKENLOWER() Converts initial alphabetic character of a token into lowercase
TOKENNEXT()  Provides an incremental tokenizer
TOKENSEP()   Provides separator before/after most recently retrieved TOKEN()
TOKENUPPER() Converts the initial letter of a token into upper case
VALPOS()     Determines numerical value of character at particular position
WORDONE()    Reduces multiple appearances of double characters to one
WORDONLY()   Finds common denominator of 2 strings on double character basis
WORDREPL()   Replaces particular double characters with others
WORDSWAP()   Exchanges double characters lying beside each other in a string
WORDTOCHAR() Exchanges double characters for individual ones