CharRLL()

CHARRLL()

Process each character in a string with bitwise ROLL LEFT operation

Syntax

      CHARRLL( <[@]cString>, <nBitsToRLL> ) --> cRLLString

Arguments

<[@]cString> string to be processed

<nBitsToRLL> number of bit positions to be rolled to the left

Returns

<cRLLString> string with bitwise rolled left characters

Description

The CHARRLL() function constructs a new string from the string passed as parameter. To do this, it performs a bitwise ROLL LEFT (RLL) operation to the characters of the string and places a character in the resulting string whose ASCII value equals to the result of that operation. Be aware that, in contrast to CHARSHL(), bits rolled out on the left are put in again on the right. If the string is passed by reference, the resulting string is stored in <cString>, too. By setting the CSETREF()-switch to .T., the return value can be omitted.

Examples

      ? charrll( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 )
      // --> Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128)+Chr(1)+Chr(2)+Chr(4)

Tests

      charrll( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 ) 
        == Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128)+Chr(1)+Chr(2)+Chr(4)

Compliance

CHARRLL() is a new function that is only available in Harbour’s CT3 lib.

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARADD(), CHARSUB(), CHARAND(), CHAROR(), CHARXOR(), CHARNOT(), CHARSHL(), CHARSHR(), CHARRLR(), CSETREF()

CharRepl()

CHARREPL()

Replacement of characters

Syntax

      CHARREPL( <cSearchString>, <[@]cString>,
                <cReplaceString>, [<lMode>] ) -> cString

Arguments

<cSearchString> is a string of characters that should be replaced

<[@]cString> is the processed string

<cReplaceString> is a string of characters that replace the one of <cSearchString>

[<lMode>] sets the replacement method (see description) Default: .F.

Returns

<cString> the processed string

Description

The CHARREPL() function replaces certain characters in <cString> with others depending on the setting of <lMode>. If <lMode> is set to .F., the function takes the characters of <cSearchString> one after the other, searches for them in <cString> and, if successful, replaces them with the corresponding character of <cReplaceString>. Be aware that if the same characters occur in both <cSearchString> and <cReplaceString>, the character on a certain position in <cString> can be replaced multiple times. if <lMode> is set to .T., the function takes the characters in <cString> one after the other, searches for them in <cSearchString> and, if successful, replaces them with the corresponding character of <cReplaceString>. Note that no multiple replacements are possible in this mode. If <cReplaceString> is shorter than <cSearchString>, the last character of <cReplaceString> is used as corresponding character for the the “rest” of <cSearchString>. One can omit the return value by setting the CSETREF() switch to .T., but then one must pass <cString> by reference to get the result.

Examples

      ? charrepl( "1234", "1x2y3z", "abcd" )            // "axbycz"
      ? charrepl( "abcdefghij", "jhfdb", "1234567890" ) // "08642"
      ? charrepl( "abcdefghij", "jhfdb", "12345" )      // "55542"
      ? charrepl( "1234", "1234", "234A" )              // "AAAA"
      ? charrepl( "1234", "1234", "234A", .T. )         // "234A"

Tests

      charrepl( "1234", "1x2y3z", "abcd" ) == "axbycz"
      charrepl( "abcdefghij", "jhfdb", "1234567890" ) == "08642"
      charrepl( "abcdefghij", "jhfdb", "12345" ) == "55542"
      charrepl( "1234", "1234", "234A" ) == "AAAA"
      charrepl( "1234", "1234", "234A", .T. ) == "234A"

Compliance

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

Platforms

All

Files

Source is charrepl.c, library is ct3.

Seealso

WORDREPL(), POSREPL(), RANGEREPL(), CSETREF()

CharRelRep()

CHARRELREP()

Replaces characters in a string depending on their correlation

Syntax

       CHARRELREP(<cSearchFor1>,<cString1>,<cSearchFor2>,
              <cString2>,<cReplaceExpression>) --> cString

Arguments

<cSearchFor1> Designates one or more characters within <cString1> for which to search.

<cString1> Designates the character string where <cSearchFor1> is found. <cSearchFor2> Designates one or more characters within <cString2> for which to search.

<cString2> [@] Designates the character string where <cSearchFor2> is found.

<cReplaceExpression> Designates one or more characters to replace those at the established corresponding position within <cString2>.

Returns

The processed <cString2> is returned.

Description

This function is easier to use than it seems. If we proceed on the assumption that both search expressions and the replacement expression are only one character long, then the following steps occur: . All positions are determined where <cSearchFor1> is found within <cString1>. . All positions are found where <cSearchFor2> is found within <cString2>. . The character in the <cString2> string is replaced by the character in the <cReplaceExpression>. This function can be used to simplify work with variables that contain screen memory. If cPict1 contains the character “|”at position 34 and cPict2 contains the character “-” at the same position, then this position within cPict2 can be replaced with a new character, “+”‘, which represents the combination of the two. Multiple Exchanges Both search expressions and the replacement expression can be longer than one character. The previously described exchange procedure occurs repeatedly — initially with the first character in the three character strings, then with the second, and so on. The number of iterations is regulated by the length of <cSearchFor1>. If <cSearchFor2> or the <cReplaceExpression> are shorter, then the last byte is used again.

Notes

. The length of <cString2> determines the number of search procedures at any one time. The length of <cSearchFor1> determines the number of possible exchanges. . The return value of this function can be suppressed by implementing CSETREF() to save space in working memory. . A use for multiple replacement using CHARRELREP() can be found in the accompanying sample programs.

Example

       Determine every position where a "b" occurs in the first string and a
           "1" occurs in the second string.  The respective character is then
           exchanged for the one designated as the fifth parameter.
           ? CHARRELREP("b", "b b b b", "1", "bbb11111", "x")
                                                             //"bbb1x1x1"

See also

CHARRELA(), CSETREF(), Introduction

CharOr()

CHAROR()

Combine corresponding ASCII value of two strings with bitwise OR

Syntax

      CHAROR( <[@]cString1>, <cString2> ) --> cOrString

Arguments

<[@]cString1> first string <cString2> second string

Returns

<cOrString> string with bitwise OR combined ASCII values

Description

The CHAROR() function constructs a new string from the two strings passed as parameters. To do this, it combines the ASCII values of the corresponding characters of both strings with a bitwise OR-operation and places a character in the resulting string whose ASCII value equals to the result of that operation. If the first string is passed by reference, the resulting string is stored in <cString1>, too. By setting the CSETREF()-switch to .T., the return value can be omitted. If <cString2> is shorter than <cString1> and the last character of <cString2> has been processed, the function restarts with the first character of <cString2>.

Examples

      // set the LSB
      ? charor( "012345678", chr( 1 ) ) // --> "113355779"
      ? charor( "012345678", chr( 1 ) + chr( 3 ) ) // --> "133357779"

Tests

      charor( "012345678", chr( 1 ) ) == "113355779"
      charor( "012345678", chr( 1 ) + chr( 3 ) ) == "133357779"

Compliance

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

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARADD(), CHARSUB(), CHARNOT(), CHARAND(), CHARXOR(), CHARSHL(), CHARSHR(), CHARRLL(), CHARRLR(), CSETREF()

CharNot()

CHARNOT()

Process each character in a string with bitwise NOT operation

Syntax

      CHARNOT( <[@]cString> ) --> cNotString

Arguments

<[@]cString> string to be processed

Returns

<cNotString> string with bitwise negated characters

Description

The CHARNOT() function constructs a new string from the string passed as parameter. To do this, it performs a bitwise NOT operation to the characters of the string and places a character in the resulting string whose ASCII value equals to the result of that operation. It can be easily seen that the resulting ASCII-value equals 255 minus input ASCII value. If the string is passed by reference, the resulting string is stored in <cString>, too. By setting the CSETREF()-switch to .T., the return value can be omitted.

Examples

      ? charnot( chr( 85 ) + chr( 128 ) + chr( 170 ) + chr( 1 ) ) 
// --> chr( 170 ) + chr( 127 ) + chr( 85 ) + chr( 254 ) ? charnot( charnot( "This is a test!" ) ) --> "This is a test!"

Tests

      charnot( chr( 85 ) + chr( 128 ) + chr( 170 ) + chr( 1 ) ) ==;
chr( 170 ) + chr( 127 ) + chr( 85 ) + chr( 254 ) charnot( charnot( "This is a test!" ) ) == "This is a test!"

Compliance

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

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARADD(), CHARSUB(), CHARAND(), CHAROR(), CHARXOR(), CHARSHL(), CHARSHR(), CHARRLL(), CHARRLR(), CSETREF()

CharMirr()

CHARMIRR()

Mirror a string

Syntax

      CHARMIRR( <[@]cString>, [<lDontMirrorSpaces>] ) -> cMirroredString

Arguments

<[@]cString> is the string that should be mirrored [<lDontMirrorSpaces>] if set to .T., spaces at the end of <cString> will not be mirrored but kept at the end Default: .F., mirror the whole string

Returns

<cMirroredString> the mirrored string

Description

The CHARMIRR() function mirrors a string, i.e. the first character will be put at the end, the second at the last but one position etc.. One can use this function for index searches, but then, the spaces at the end of the string should not be mirrored. One can omit the return value of the function by setting the CSETREF() switch to .T., but <cString> must then be passed by reference to get a result.

Examples

      ? charmirr( "racecar" )        // "racecar"
      ? charmirr( "racecar  ", .T. ) // "racecar  "
      ? charmirr( "racecar  ", .F. ) // "  racecar"

Tests

      charmirr( "racecar" ) == "racecar"
      charmirr( "racecar  ", .T. ) == "racecar  "
      charmirr( "racecar  ", .F. ) == "  racecar"

Compliance

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

Platforms

All

Files

Source is charmirr.c, library is ct3.

Seealso

CSETREF()

CharAnd()

CHARAND()

Combine corresponding ASCII value of two strings with bitwise AND

Syntax

      CHARAND( <[@]cString1>, <cString2> ) --> cAndString

Arguments

<[@]cString1> first string <cString2> second string

Returns

<cAndString> string with bitwise AND combined ASCII values

Description

The CHARAND() function constructs a new string from the two strings passed as parameters. To do this, it combines the ASCII values of the corresponding characters of both strings with a bitwise AND-operation and places a character in the resulting string whose ASCII value equals to the result of that operation. If the first string is passed by reference, the resulting string is stored in <cString1>, too. By setting the CSETREF()-switch to .T., the return value can be omitted. If <cString2> is shorter than <cString1> and the last character of <cString2> has been processed, the function restarts with the first character of <cString2>.

Examples

      // clear the LSB
      ? charand( "012345678", chr( 254 ) ) // --> "002244668"
      ? charand( "012345678", chr( 254 ) + chr( 252 ) ) // --> "002044648"

Tests

      charand( "012345678", chr( 254 ) ) == "002244668"
      charand( "012345678", chr( 254 ) + chr( 252 ) ) == "002044648"

Compliance

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

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARADD(), CHARSUB(), CHARNOT(), CHAROR(), CHARXOR(), CHARSHL(), CHARSHR(), CHARRLL(), CHARRLR(), CSETREF()

CharAdd()

CHARADD()

Adds corresponding ASCII value of two strings

Syntax

      CHARADD( <[@]cString1>, <cString2> ) --> cAddString

Arguments

<[@]cString1> first string <cString2> second string

Returns

<cAddString> string with added ASCII values

Description

The CHARADD() function constructs a new string from the two strings passed as parameters. To do this, it adds the ASCII values of the corresponding characters of both strings and places a character in the resulting string whose ASCII value equals to that sum (modulo 256). If the first string is passed by reference, the resulting string is stored in <cString1>, too. By setting the CSETREF()-switch to .T., the return value can be omitted. If <cString2> is shorter than <cString1> and the last character of <cString2> has been processed, the function restarts with the first character of <cString2>.

Examples

      ? charadd( "012345678", chr( 1 ) ) // --> "123456789"
      ? charadd( "123456789", chr( 255 ) ) // --> "012345678"
      ? charadd( "0000", chr( 0 ) + chr( 1 ) + chr( 2 ) + chr( 3 ) )
                  // --> "0123"

Tests

      charadd( "012345678", chr( 1 ) ) == "123456789"
      charadd( "012345678", chr( 1 ) + chr( 2 ) ) == "133557799"
      charadd( "123456789", chr( 255 ) ) == "012345678"
      charadd( "123456789", chr( 255 ) + chr( 254 ) ) == "002244668"

Compliance

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

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARSUB(), CHARAND(), CHARNOT(), CHAROR(), CHARXOR(), CHARSHL(), CHARSHR(), CHARRLL(), CHARRLR(), CSETREF()

Harbour All Functions – C

CD / CHDIR / DirChange

CDoW

Chr

CharAdd
CharAnd
CharEven
CharHist
CharList
CharMirr
CharMix
CharNoList
CharNot
CharOdd
CharOne
CharOnly
CharOr
CharPix
CharRela
CharRelRep
CharRem
CharRepl
CharRLL
CharRLR
CharSHL
CharSHR
CharSList
CharSort
CharSub
CharSwap
CharWin
CharXOR

CLIPINIT
CMonth

Col

Cos

CosH

CountLeft
CountRight

CToBit

CToD

CToDoW
CToF
CToMonth
CToN

CurDir

CSetArgErr
CSetAtMuPa
CSetRef
CTCExit
CTCInit
CTExit
CTInit

CT_CSETREF

 CSETREF()
 Determines whether or not reference sensitive functions return a value
------------------------------------------------------------------------------
 Syntax

     CSETREF([<lNewSwitch>]) --> lOldSwitch

 Argument

     <lNewSwitch>  Designates whether the return value is suppressed for
     specified functions.  When this parameter is .T., it suppresses the
     return value of the functions listed below.  When the parameter is .F.
     (default value), these functions return a value.

 Returns

     If no parameter is specified, the function returns the current setting.
     If a parameter is specified, the function returns the previous setting.

 Description

     A series of Clipper Tools functions enable you to pass parameters by
     reference.  After executing the function, the passed parameter already
     contains the result.  However, each of these functions also returns this
     result as a value.  A copy of the passed string exists for a short time
     in working memory, but it is invisible to you.  In the worst possible
     case, two adjoining memory blocks would require up to 64 kB.

     This behavior can be influenced by implementing CSETREF(.T.).  Then the
     group of affected string functions no longer return a value, which can
     save you up to 64k of memory with large strings.

           Functions affected by CSETREF():

           ADDASCII()   BLANK()         CHARADD()

           CHARAND()    CHARMIRR()      CHARNOT()

           CHAROR()     CHARRELREP()    CHARREPL()

           CHARSORT()   CHARSWAP()      CHARXOR()

           CRYPT()      JUSTLEFT()      JUSTRIGHT()

           POSCHAR()    POSREPL()       RANGEREPL()

           REPLALL()    REPLLEFT()      REPLRIGHT()

           TOKENLOWER() TOKENUPPER()    WORDREPL()

           WORDSWAP()

 Note

     .  If, in spite of having CSETREF(.T.), you need one of the
        previously listed functions to return a value, then the target
        variable contains .F. instead of the anticipated string.

 Examples

     .  Here is how CSETREF() is set to .F.:

        CSETREF(.F.)
        cStr1  :=  "HAGBDCFE"
        cStr2  :=  CHARSORT(@cStr1)
        ? cStr1, cStr2        // "ABCDEFGH" - cStr1,cStr2 are identical

     .  Here is how CSETREF() is set to .T.:

        CSETREF(.T.)

        cStr1  :=  "HAGBDCFE"
        cStr2  :=  CHARSORT(@cStr1)
        ? cStr1               // "ABCDEFGH" - Sort cStr1
        ? cStr2               // .F.

     .  Determine when memory will be needed:

        cStr1  :=  SPACE(32000)       // Create large string

        CSETREF(.F.)
        CHARSORT(@cStr1)              // Additional 32000 bytes

        CSETREF(.T.)
        CHARSORT(@cStr1)              // Needs no additional memory

See Also: Introduction