AtToken()

AtToken()

Position of a token in a string

Syntax

      AtToken( <cString>, [<cTokenizer>],
               [<nTokenCount>], [<nSkipWidth>] ) -> nPosition

Arguments

<cString> is the processed string

[<cTokenizer>] is a list of characters separating the tokens in <cString> Default: chr(0) + chr(9) + chr(10) + chr(13) + chr(26) +  chr(32) + chr(32) + chr(138) + chr(141) +  “, .;:!\?/\\<>()#&%+-*”

[<nTokenCount>] specifies the count of the token whose position should be calculated Default: last token

[<nSkipWidth>] specifies the maximum number of successive tokenizing characters that are combined as ONE token stop, e.g. specifying 1 can yield to empty tokens Default: 0, any number of successive tokenizing characters are combined as ONE token stop

Returns

<nPosition> The start position of the specified token or 0 if such a token does not exist in <cString>.

Description

The AtToken() function calculates the start position of tne <nTokenCount>th token in <cString>. By setting the new <nSkipWidth> parameter to a value different than 0, you can specify how many tokenizing characters are combined at most to one token stop. Be aware that this can result to empty tokens there the start position is not defined clearly. Then, AtToken() returns the position there the token WOULD start if its length is larger than 0. To check for empty tokens, simply look if the character at the returned position is within the tokenizer list.

Examples

      AtToken( "Hello, World!" ) // --> 8  // empty strings after tokenizer
                                           // are not a token !

Tests

      AtToken( "Hello, World!" ) == 8
      AtToken( "Hello, World!",, 2 ) == 8
      AtToken( "Hello, World!",, 2, 1 ) == 7
      AtToken( "Hello, World!", " ", 2, 1 ) == 8

Compliance

AtToken() is compatible with CT3’s AtToken, but has an additional 4th parameter to let you specify a skip width equal to that in the TOKEN() function.

Platforms

All

Files

Source is token1.c, library is libct.

Seealso

Token(), NumToken(), TokenLower(), TokenUpper(), TokenSep()

Advertisements

AtRepl()

AtRepl()

Search and replace sequences in a string

Syntax

      AtRepl( <cStringToMatch>, <cString>, <cReplacement>, [<nCounter>],
              [<lMode>], [<nIgnore>] ) --> cString

Arguments

<cStringToMatch> is the substring searched for in <cString>

<cString> is the processed string

<cReplacement> is the replacement for sequences found

[<nCounter>] specifies the number of replacements Default: last occurence

[<lMode>] if set to .T., only the <nCounter>th sequence of <cStringToMatch> will be replaced, else all sequences will be replaced. Default: .F.

[<nIgnore>]) specifies how many characters in <cString> from the beginning should be ignored by the function Default: 0

Returns

<cString>

Description

The AtRepl() function searches and replaces sequences in a string. First, the function ignores the first <nIgnore> characters of <cString>. Then, if <lMode> is set to .T., it searches for the <nCounter>th occurence of <cStringToMatch> in <cString>. If successful, the sequence will be replaced with <cReplacement>. If <lMode> is set to .F., the same search is performed, but EVERY occurence of <cStringToMatch> till the <nCounter>th (inclusive) will be replaced with <cReplacement>. Note that, in this case, the replacements are performed even if the <nCounter>th occurence does not exist. By using the CSETATMUPA() switch you can decide whether the function restarts searching after a found sequence of after the first character of that sequence. The function allows the use of wildcards in <cStringToMatch> and looks for the settings of SETATLIKE().

Examples

      ? AtRepl( "ABC", "ABCDABCDABC", "xx" )    // --> "xxDxxDxx"
      ? AtRepl( "ABC", "ABCDABC", "ZYXW" )      // --> "ZYXWDZYXW"
      ? AtRepl( "ABC", "ABCDABCDABC", "xx", 2 ) // --> "xxDxxDABC"
      ? AtRepl( "ABC", "ABCDABCDABC", "xx", 2, .T. )  // --> "ABCDxxDABC"

Tests

      AtRepl( "ABC", "ABCDABCDABC", "xx" ) == "xxDxxDxx"
      AtRepl( "ABC", "ABCDABC", "ZYXW" ) == "ZYXWDZYXW"
      AtRepl( "ABC", "ABCDABCDABC", "xx", 2 ) == "xxDxxDABC"
      AtRepl( "ABC", "ABCDABCDABC", "xx", 2, .T. ) == "ABCDxxDABC"

Compliance

AtRepl() is compatible with CT3’s AtRepl(). Note the new, 6th parameter !

Platforms

All

Files

Source is AtRepl.c, library is ct3.

Seealso

CSETATMUPA() SETATLIKE()

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()

AtAdjust()

AtAdjust()

Adjusts a sequence within a string to a specified position

Syntax

      AtAdjust( <cStringToMatch>, <cString>, <nAdjustPosition>,
                [<nCounter>], [<nIgnore>],
                [<nFillChar|cFillChar>] ) -> cString

Arguments

<cStringToMatch> is the sequence to be adjusted within <cString>

<cString> is the string that contains <cStringToMatch>

<nAdjustPosition> specifies the position to that <cStringToMatch> will be adjusted

[<nCounter>] specifies which occurence of <cStringToMatch> in <cString> is to be adjusted. Default: last occurence

[<nIgnore>] specifies how many characters should be omitted in the scan

[<nFillChar|cFillChar>] specifies the character that is used for the adjustment

Returns

<cString> the changed string

Description

The function first looks for the <cSearchFor> parameter within the character string. From this point, the rest of the <cString> is moved (adjusted) by either inserting or removing blanks until the <nTargetPosition> is reached. In lieu of blanks, <nCharacter> | <cCharacter> can be used as a fill character.

Additionally you can specify that the nth occurrence of be used and whether or not a specific number of characters at the beginning of the search string is eliminated.

Note

Using CSETATMUPA() can influence how the search is performed.

Using SETATLIKE() permits the use of wild cards within the search sequence.

Examples

     .  Align comments at column 60.  The search is for the first
        occurrence of "//".  Since there is usually at least one space before
        each "//", search for " //":

        ? AtAdjust(" //", Line, 60, 1)

     .  Move the extensions for the following list of file names to
        position 10 and eliminate the ".":

        WINDOW.DBF
        PLZ.DBF
        BACK.DBF
        HELP.DBF
        LOG.DBF

        CHARREM(".", AtAdjust(".", File, 10))

        WINDOW      DBF

        PLZ         DBF
        BACK        DBF
        HELP        DBF
        LOG         DBF

Use AtAdjust() with CSETATMUPA(). There is always a problem determining whether “AA” occurs twice or three times in “AAA”. Depending on CSETATMUPA(), the function searches behind the last character, or starts from the last character of a located sequence:

        CSETATMUPA(.F.)
        ? AtAdjust("AA", "123AAABBB", 7, 2)       // Sequence not found

        CSETATMUPA(.T.)
        ? AtAdjust("AA", "123AAABBB", 7, 2)       // "123A  AABBB"

Compliance

AtAdjust() works like CT3’s AtAdjust()

Platforms

All

Files

Source is AtAdjust.c, library is ct3.

Seealso

SETATLIKE(), CSETATMUPA()

ASCPos()

ASCPos()

ASCII value of a character at a certain position

Syntax

      ASCPos( <cString>, [<nPosition>] ) --> nAsciiValue

Arguments

<cString> is the processed string

[<nPosition>] is an optional position within <cString> Default: last position in <cString>

Returns

<nAsciiValue> the ASCII value of the character at the specified position

Description

The ASCPos() function returns the ASCII value of the character that can be found at the position <nPosition> in <cString>. If <nPosition> is larger than the length of <cString>, 0 is returned.

Examples

      ? ASCPos( "0123456789" ) // --> 57
      ? ASCPos( "0123456789", 1 ) // --> 48

Tests

      ASCPos( "0123456789" ) == 57
      ASCPos( "0123456789", 1 ) == 48
      ASCPos( "0123456789", 11 ) == 0  // <nPosition> to large !

Compliance

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

Platforms

All

Files

Source is asciisum.c, library is libct.

Seealso

VALPOS()

ASCIISum()

ASCIISum()

Calculate the sum of the ASCII values of the characters in a string

Syntax

      ASCIISum( <cString> ) --> nASCIISum

Arguments

<cString> the string to be processed

Returns

<nASCIISum> sum of the ASCII values in <cString>

Description

The ASCIISum() function sums up the ASCII values of the characters in <cString>. Be aware that the function is not position sensitive, i.e. a change of position of a certain character in the string does not change the ascii sum.

Examples

      ? ASCIISum( "ABC" ) // -->  197
      ? ASCIISum( "ACB" ) // -->  197

Tests

      ASCIISum( Replicate( "A", 10000 ) ) == 650000
      ASCIISum( "0123456789" ) == 525
      ASCIISum( NIL ) == 0

Compliance

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

Platforms

All

Files

Source is ASCIISum.c, library is ct3.

Seealso

CHECKSUM()

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()