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

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

AddMonth()

AddMonth()

Adds or subtracts months to/from a date

Syntax

      AddMonth( [<dDate>,] <nMonths> ) -> dShiftedDate

Arguments

<dDate>Designates the date to which the months is added.

The default is the system date.

<nMonth>Designates the number of months to add to <dDate>.

Returns

AddMonth() returns the new date after <nMonth> is added to <dDate>.

Description

Use this function to calculate payment due dates based on an invoice date and for similar applications. It permits you to add months to a given date. If you use a negative number, months are subtracted.

Note

An empty date parameter will result in an empty date.

Examples

     * Show today's date, plus 36 months:

     ? "The payment period ends on: ", AddMonth(36)

     * Today plus 7 month: 
     ? "AddMonth( 7 ) :", AddMonth( 7 )

     * Date of last day of 7 month after :
     ? "EOM( AddMonth( 7 ) ) :", EOM( AddMonth( 7 ) )

     * Dates of next year: 
     dDate := CTOD( "12.12.2012" )
     ? "Last day of one month after", dDate, ":", EOM( AddMonth( dDate, 1 ) )
     ? "Last day of two month after", dDate, ":", EOM( AddMonth( dDate, 2 ) )

     * Month before 
     ? "Date of two month before", dDate, ":", AddMonth( dDate, -2 )
     ?

Compliance

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

Platforms

All

Files

Source is dattime2.prg, library is libct.

AddASCII()

ADDASCII()

Add an integer value to an ascii value of a string

Syntax

      ADDASCII( <[@]cString>, <nValue>, [<nPosition>], [<lCarryOver>] ) --> cString

Arguments

<[@]cString> is the string that should be edited

<nValue> is a integer value that should be added to the ASCII value of the character at the <nPosition>th position

[<nPosition>] is the position of the character that should be edited. If not supplied, the last character of <[@]cString> is edited.

[<lCarryOver>] NEW: is set to .T. if the substring from position 1 to position <nPosition> should be treated as an integer written to the base 256. Thus, the addition of <nValue> can affect to whole substring (see EXAMPLES). Default is .F., the original behaviour of this function.

Returns

The edited string is returned. The return value can be suppressed by using the CSETREF() function. The string must then be passed by reference [@].

Description

ADDASCII() can be used to add or subtract integer values from ASCII values in a string. The new <lCarryOver> parameter allows to treat a string as an integer written to the base 256. Since <nValue> is limited to a signed long, only substrings 4 characters long can be affected by one ADDASCII() call. If the length of <[@]cString> is smaller than <nPosition>, the string remains unchanged. The same happens, if uninterpretable parameters are passed to this function.

Examples

      // Add 32 to the ASCII value of the character at the last position
      // in the string

      ? addascii( "SmitH", 32 ) // --> "Smith"

      addascii( "0000", 1, 1 ) == "1000"
      addascii( "0000", 1 ) == "0001"
      addascii( "AAAA", -255, 1 ) == "BAAA"
      addascii( "AAAA", -255 ) == "AAAB"
      addascii( "AAAA", 1, 2, .T. ) == "ABAA"
      addascii( "AAAA", 257, 2, .T. ) == "BBAA"
      addascii( "AAAA", 257, 2, .F. ) == "ABAA"
      addascii( "AAAA", 258,, .T. ) == "AABC"
      addascii( "ABBA", -257, 3, .T. ) == "AAAA"

Compliance

ADDASCII() is compatible with CT3’s ADDASCII(). A new, 4th, parameter has been added who defaults to the original behaviour if omitted.

Platforms

All

Files

Source is addascii.c, library is ct3.

Seealso

CSETREF()