CharXOR()

CHARXOR()

Combine corresponding ASCII value of two strings with bitwise XOR

Syntax

      CHARXOR( <[@]cString1>, <cString2> ) --> cXOrString

Arguments

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

Returns

<cXOrString> string with bitwise XOR combined ASCII values

Description

The CHARXOR() 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 XOR-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

      // easy encryption
      ? charxor( "This is top secret !", "My Password" ) // --> <encrypted sentence>

Tests

      charxor( charxor( "This is top secret !", "My Password" ), "My Password" ) == "This is top secret !"

Compliance

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

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

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

Advertisements

CharWin()

CHARWIN()

Exchanges particular characters in a screen area.

Syntax

       CHARWIN([<nTopline>,<nLeftcolumn>,<nBottomline>,
              <nRightcolumn>, [<cNewcharacter|nNewcharacter>],
              [<cOldcharacter|nOldcharacter>]]) --> cNull

Arguments

<nTopline> Designates the line for the top-left corner of the area.

<nLeftcolumn> Designates the column for the top-left corner the area.

<nBottomline> Designates the line for the bottom-right corner of the area.

<nRightcolumn> Designates the column for the bottom-right corner of the area.

<cNewcharacter|nNewcharacter> Designates the new character for the screen area. Specify the parameter as a numeric in the range of 0 to 255 or as a character string. The default value is the CLEARB.

<cOldcharacter|nOldcharacter> Designates which character to exchange. Specify the parameter as a numeric in the range of 0 to 255 or as a character string. The default is to exchange all characters.

() When no parameter is designated, the function replaces all characters in the screen area with CLEARB.

Returns

The function always returns a null string.

Description

Within a screen area, CHARWIN() replaces all characters or just a particular character with a new one. If <cNewcharacter|nNewcharacter> is not designated, the function uses the character set with SETCLEARB(), where the preset value is CHR(255). The upper-left and lower-right corner rows and columns are given for the borders of the area. If these arguments are missing, then the entire screen area is exchanged.

Examples

       .  Exchange all characters for CLEARB:
              SETCLEARB("X")       // Exchanges within CHARWIN() entire screen
           .  Exchange all "A" for "B":
              CHARWIN(10, 10, 20, 70, "B", "A")    // Always returns a ("") null
                                                   // string
           .  Numeric characters can also be designated:
              CHARWIN(10, 10, 20, 70, 66, 65)      // A = 65, B = 66

See also

SETCLEARB(), COLORWIN(), Introduction

CharSwap()

CHARSWAP()

Swap neighbouring characters in a string

Syntax

      CHARSWAP( <[@]cString> ) -> cSwappedString

Arguments

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

Returns

<cSwappedString> a string where neighbour characters are swapped

Description

The CHARSWAP() function loops through <cString> in steps of two characters and exchanges the characters from the odd and the even positions. By setting the CSETREF() switch to .T., one can omit the return value of this functin, but one must then pass <cString> by reference.

Examples

      ? CHARSWAP( "0123456789" )   // "1032547698"
      ? CHARSWAP( "ABCDEFGHIJK" )  // "BADCFEHGJIK"

Tests

      CHARSWAP( "0123456789" )  == "1032547698"
      CHARSWAP( "ABCDEFGHIJK" ) == "BADCFEHGJIK"

Compliance

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

Platforms

All

Files

Source is charswap.c, library is libct.

Seealso

WORDSWAP(), CSETREF()

CharSub()

CHARSUB()

Subtracts corresponding ASCII value of two strings

Syntax

      CHARSUB( <[@]cString1>, <cString2>) --> cSubString

Arguments

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

Returns

<cSubString> string with subtracted ASCII values

Description

The CHARSUB() function constructs a new string from the two strings passed as parameters. To do this, it subtracts the ASCII values of the corresponding characters of both strings and places a character in the resulting string whose ASCII value equals to that difference (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

      ? charsub( "012345678", Chr( 1 ) ) // --> "/01234567"
      ? charsub( "123456789", Chr( 255 ) ) // --> "23456789:"
      ? charsub( "9999", Chr( 0 ) + Chr( 1 ) + Chr( 2 ) + Chr( 3 ) ) // --> "9876"

Tests

      charsub( "123456789", Chr( 1 ) ) == "012345678"
      charsub( "123456789", Chr( 1 ) + Chr( 2 ) ) == "002244668"
      charsub( "012345678", Chr( 255 ) ) == "123456789"
      charsub( "012345678", Chr( 255 ) + Chr( 254 ) ) == "133557799"

Compliance

CHARSUB() 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(), CHARAND(), CHARNOT(), CHAROR(), CHARXOR(), CHARSHL(), CHARSHR(), CHARRLL(), CHARRLR(), CSETREF()

CharSort()

CHARSORT()

Sort sequences within a string.

Syntax

      CHARSORT( <[@]cString>, [<nElementLength>], [<nCompareLength>],
                [<nIgnoreCharacters>], [<nElemenOffset>], [<nSortLength>],
                [<lDescending>] ) -> cSortedString

Arguments

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

[<nElementLength>] specifies the length of the elements that should be sorted Default: 1

[<nCompareLength>] specifies how many characters within one element should be used for comparison Default: <nElementLength>

[<nIgnoreCharacters>] specifies the number of characters at the beginning of <cString> that should be ignored in the sort process Default: 0

[<nElementOffset>] specifies the offset of the comparison string within a element Default: 0 [<nSortLength>] specifies how many characters in <cString>, starting from the <nIgnoreCharacters> position, should be sorted Default: len(cString)-nIgnoreCharacters

[<lDescending>]) specifies whether the process should sort descending or not

Returns

<cSortedString> the string resulting from the sort process

Description

The CHARSORT function sorts the characters within a string <cString>. With the parameters <nIgnoreCharacters> and <nSortLength>, you can determine that only the substring from position <nIgnoreCharacters>+1 to position <nIgnoreCharacters>+<nSortLength> within <cString> should be sorted. The sorting algorithm is determined with the other parameters. <nElementLength> specifies the length of one element, i.e. there are <nSortLength>/<nElementLength> elements that are sorted. Note that surplus characters are not sorted but stay at their position. To do the sorting, the function uses the Quicksort algorithm implemented in the C-lib qsort() function. This algorithm needs to know how to compare and order two elements. This is done by comparing the ASCII values of a substring within each element. This substring is determined by the parameters <nElementOffset> and <nCompareLength> and the order by <lDescending>. By setting the CSETREF() switch to .T., one can omit the return value of the function, but one must then pass <cString> by reference.

Examples

      ? CHARSORT( "qwert" )                     // "eqrtw"
      ? CHARSORT( "qwert", 2 )                  // "erqwt"
      ? CHARSORT( "b1a4a3a2a1", 2, 1 )          // "a2a1a3a4b1"
      ? CHARSORT( "XXXqwert", 1, 1, 3 )         // "XXXeqrtw"
      ? CHARSORT( "b1a4a3a2a1", 2, 1, 0, 1 )    // "a1b1a2a3a4"
      ? CHARSORT( "384172852", 1, 1, 0, 0, 4 )  // "134872852"
      ? CHARSORT( "qwert", .T. )                // "wtrqe"

Tests

      CHARSORT( "qwert" )                     == "eqrtw"
      CHARSORT( "qwert", 2 )                  == "erqwt"
      CHARSORT( "b1a4a3a2a1", 2, 1 )          == "a2a1a3a4b1"
      CHARSORT( "XXXqwert", 1, 1, 3 )         == "XXXeqrtw"
      CHARSORT( "b1a4a3a2a1", 2, 1, 0, 1 )    == "a1b1a2a3a4"
      CHARSORT( "384172852", 1, 1, 0, 0, 4 )  == "134872852"
      CHARSORT( "qwert", .T. )                == "wtrqe"

Compliance

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

Platforms

All

Files

Source is charsort.c, library is ct3.

Seealso

CSETREF()

CharSList()

CHARSLIST()

Generates a sorted list of all characters in a string

Syntax

      CHARSLIST( [<cString>] ) -> cSortedCharacterList

Arguments

[<cString>] is the string for whom the function generates a sorted list of all characters Default: “” (empty string)

Returns

<cSortedCharacterList> a sorted list of the characters in <cString>

Description

The CHARLIST() function generates a sorted list of those characters that are contained in <cString>. This list can contain each character only once, so that its maximum length is 256. The function gives the same result as CHARSORT(CHARLIST(<cString>))

Examples

      ? charslist( "Hello World !" ) // --> " !HWdelor"

Tests

      charslist( "Hello World !" ) == " !HWdelor"
      charslist( "Hello World !" ) == charsort (charlist ("Hello World !"))
      charslist( NIL ) == ""

Compliance

CHARSLIST() is only available in Harbour’s CT3 library.

Platforms

All

Files

Source is charlist.c, library is libct.

Seealso

CHARNOLIST(), CHARLIST(), CHARHIST()

CharSHR()

CHARSHR()

Process each character in a string with bitwise SHIFT RIGHT operation

Syntax

      CHARSHR( <[@]cString>, <nBitsToSHR> ) --> cSHRString

Arguments

<[@]cString> string to be processed

<nBitsToSHR> number of bit positions to be shifted to the right

Returns

<cSHRString> string with bitwise shifted right characters

Description

The CHARSHR() function constructs a new string from the string passed as parameter. To do this, it performs a bitwise SHIFT RIGHT (SHR) 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 bits shifted out of the byte are lost. If you need a bit rotation, use the CHARRLR() function instead. 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

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

Tests

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

Compliance

CHARSHR() 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(), CHARRLL(), CHARRLR(), CSETREF()